AngularJS使用templateHtml的路径作为模块名称

前端之家收集整理的这篇文章主要介绍了AngularJS使用templateHtml的路径作为模块名称前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我注意到AngularJS UI Bootstrap对模板使用以下方法

angular.module("uib/template/progressbar/bar.html",[]).run(["$templateCache",function($templateCache) {
  $templateCache.put("uib/template/progressbar/bar.html" }

所以我认为这是一个非常好的解决方案但是为每个模板创建模块的原因是什么,例如angular.module(“uib / template / progressbar / bar.html”或angular.module(“uib / template / progressbar / progress.html”) “等等

它会给我们带来什么好处?

解决方法

分别为每个模板设置一个模块将导致代码的正确分离.每个模块都将为每个模板添加代码,并防止用户混合代码.一个普遍的规则是,一个功能或实体应该只履行自己的职责而不是那个职责.

猜你在找的Angularjs相关文章