我最近在我的 yeoman 应用程序中引入了 Angular Directive(指令)用于模板化,如果我 grunt 为应用程序的正常开发版本提供服务,一切正常,但是当我用 grunt 构建“dist”文件夹并提供它时,html 中的我的应用程序的指令没有出现在页面上并且控制台记录了这个错误:
Failed to load resource: the server responded with a status of 404 (Not Found)
vendor.6e8f248d.js:5 Error: [$compile:tpload] Failed to load template:
/views/tabdir.html (HTTP status: 404 Not Found)
我读到依赖注入(inject)需要采用数组格式,这样缩小就不会干扰它,所以我对我的所有 Controller 都这样做了,但同样的问题仍然存在。例如:
angular.module('MainApp').controller('MainCtrl', ['$scope', 'inputBlur', function ($scope, inputBlur) {
}]);
是什么导致 grunt 无法正确加载我的指令?
最佳答案
我遇到了类似的问题。删除指令的 templateUrl
值中的第一个斜杠 /
,应该是这样的:
templateUrl:'views/tabdir.html'
关于javascript - Angular/grunt 无法加载模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35399087/