【发布时间】:2014-09-30 07:52:37
【问题描述】:
我正在使用 gulp (html2js) 将我所有的 html 编译成 angular 的 $templateCache 和 browserify,然后包含我想要的文件。
但是,我是 angular 的新手,当我使用 $templateCache 时,angular 仍然会尝试在模板中使用 ajax,这对我来说似乎不合适。
//views.min.js - This has exported correctly as far as I can tell
!function(e){try{e=angular.module("Views")}catch(t){e=angular.module("Views",[])}e.run(["$templateCache",function(e){e.put("sliderHome.html",'<div class="slider royalSlider rsDefault"><div ng-repeat="item in sliderItems"><h1>{{item.title}}</h1><p>{{item.text}}</p><img ng-src="/img/news/{{item.number}}.jpg"></div></div>')}])}(),function(e){try{e=angular.module("Views")}catch(t){e=angular.module("Views",[])}e.run(["$templateCache",function(e){e.put("results/resultsGrid.html","<div>Results List as is the best</div>")}])}();
上面的文件是使用browserify 包含的,我可以在文件底部看到它。
app.js - 角度
app.directive('sliderDirect', function($timeout, $templateCache) {
return {
restrict: 'E',
templateUrl: $templateCache.get('sliderHome.html')
....
}
});
出现错误
GET http://localhost:3001/%3Cdiv%20class=%22slider%20royalSlider%20rsDefault%22…0ng-src=%22/img/news/%7B%7Bitem.number%7D%7D.jpg%22%3E%3C/div%3E%3C/div%3E 404 (Not Found)
那么为什么我不能使用$templateCache 而不像你所期望的那样尝试 ajax 呢?
【问题讨论】:
标签: javascript ajax angularjs gulp