【发布时间】:2015-08-25 15:27:20
【问题描述】:
当我尝试使用 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('/');
};
}
};
});
这是我的“应用”文件夹的树形视图
|-- 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 开发人员工具显示源选项卡中没有 app 文件夹(它只显示 'bower_components'、'scripts' 、'styles' 和 index .html
**更新**
看来,angular 看不到的唯一文件夹是 app 中的 views 文件夹。我不确定问题出在哪里。 grunt会不会有问题?
ngtemplates: {
dist: {
options: {
module: 'stockDogApp',
htmlmin: '<%= htmlmin.dist.options %>',
usemin: 'scripts/scripts.js'
},
cwd: '<%= yeoman.app %>',
src: 'views/{,*/}*.html',
dest: '.tmp/templateCache.js'
}
},
【问题讨论】:
-
这是在运行缩小代码吗?还是只是运行“grunt serve”?
-
你解决了吗,因为如果你解决了我就卡在它上面
-
只是重新重写了整个东西..由于某些奇怪的原因工作得很好
-
你是怎么解决这个问题的? :S
-
@IvanCoronado - 只是再次重写了整个文件.. 然后它工作了:S ...所以我不确定我到底哪里出错了
标签: javascript angularjs gruntjs bower