当我尝试使用 Angular 运行本地项目时,我从 Chrome 收到 404 状态。我不确定问题出在哪里,并且我已经尝试过类似问题的建议答案。
这是我的指令文件:
'use strict';
/**
* @ngdoc directive
* @name stockDogApp.directive:stkWatchlistPanel
* @description
* # stkWatchlistPanel
*/
angular.module('stockDogApp')
.directive('stkWatchlistPanel', function ($location, $modal, WatchlistService) {
return {
templateUrl: 'views/templates/watchlist-panel.html',
restrict: 'E',
scope : {},
link: function($scope){
$scope.watchlist = {};
var addListModal = $modal({
scope : $scope,
template: 'views/templates/addlist-modal.html',
show : false
});
$scope.watchlists = WatchlistService.query();
$scope.showModal = function(){
addListModal.$promise.then(addListModal.show);
};
$scope.createList = function(){
WatchlistService.save($scope.watchlist);
addListModal.hide();
$scope.watchlist = {};
};
$scope.deleteList = function(list){
WatchlistService.remove(list);
$location.path('/');
};
}
};
});
这是我的“app”文件夹的树视图
|-- 404.html
|-- favicon.ico
|-- images
| `-- yeoman.png
|-- index.html
|-- robots.txt
|-- scripts
| |-- app.js
| |-- controllers
| |-- directives
| | `-- stk-watchlist-panel.js
| `-- services
| `-- watchlist-service.js
|-- styles
| `-- main.css
`-- views
`-- templates
|-- addlist-modal.html
`-- watchlist‐panel.html
当我在控制台中加载 index.html 时,出现页面未找到错误。
Error: [$compile:tpload] Failed to load template: views/templates/watchlist-panel.html (HTTP status: 404 Not Found)
http://errors.angularjs.org/1.4.4/$compile/tpload?p0=views%2Ftemplates%2Fwatchlist-panel.html&p1=404&p2=Not%20Found
我还尝试输入根文件夹的完整路径,但仍然没有检测到该页面。
我不确定这是否是原因,但查看 chrome 开发人员工具显示源选项卡中没有应用程序文件夹(它只显示 'bower_components'、'scripts' 、 'styles' 和 index.html
**更新 **
看来 Angular 唯一看不到的文件夹是应用程序中的视图文件夹。我不确定问题出在哪里。 grunt 可能有问题吗?
ngtemplates: {
dist: {
options: {
module: 'stockDogApp',
htmlmin: '<%= htmlmin.dist.options %>',
usemin: 'scripts/scripts.js'
},
cwd: '<%= yeoman.app %>',
src: 'views/{,*/}*.html',
dest: '.tmp/templateCache.js'
}
},