Angular / grunt failed to load template

馋奶兔 提交于 2020-01-23 09:54:17

问题


I recently introduced angular directives into my yeoman app for templating, and everything works fine if I grunt serve the normal dev version of the app, but when I build the 'dist' folder with grunt and serve it, the html in the directives of my app don't appear on the page and the console logs this error:

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)

I read that dependency injection needs to be in an array format so that minification doesn't mess with it, and so I did this for all of my controllers, but the same problem still persists. Eg:

angular.module('MainApp').controller('MainCtrl', ['$scope', 'inputBlur', function ($scope, inputBlur) {

}]);

What is causing my directives to not be loaded correctly by grunt?


回答1:


I had a similar issue. Remove the first foreslash / in the templateUrl value of your directive, should be like this:

templateUrl:'views/tabdir.html'


来源:https://stackoverflow.com/questions/35399087/angular-grunt-failed-to-load-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!