[英]First angular app not loading routes
I've been trying to follow Dan Wahlin's YT video and implement it in a parallel way using my own data. 我一直在尝试跟踪Dan Wahlin的YT视频,并使用我自己的数据以并行方式实现它。 The backend is in express and mongo, and the code below worked up until the point that I started adding routes. 后端在express和mongo中,下面的代码工作到我开始添加路由为止。 The two files linked to exist, and everything is running on a server, which rules out the issues of similar posters, but the partials are not loading (I see some signs that the ng-view stub has been changed by angular, but without injecting the new content). 链接到的两个文件存在,并且所有文件都在服务器上运行,这排除了类似发帖人的问题,但是未加载部分文件(我看到一些迹象表明ng-view存根已被角度更改,但未注入新内容)。 Any clues? 有什么线索吗?
<html ng-app="restosApp">
<head>
</head>
<body>
<div>
<div data-ng-view></div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.2/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.2/angular-route.min.js"></script>
<script>
var app = angular.module('restosApp', ['ngRoute']);
app.controller('listController', function($scope, restosFactory) {
function init() {
restosFactory.getQnames().success(function(data){
$scope.qnames = data;
});
}
init();
});
app.controller('editorController', function($scope, restosFactory) {
function init() {
restosFactory.getFullData('marius').success(function(data){
$scope.resto = data;
});
}
init();
});
app.config(function ($routeProvider) {
$routeProvider
.when('/', {
controller: 'listController',
templateURL: 'qname.html'
})
.when('/edit', {
controller: 'editorController',
templateURL: 'editor.html'
})
.otherwise({
redirectTo: '/'
});
});
app.factory('restosFactory', function($http){
var factory = {};
factory.getQnames = function() {
return $http.get('http://localhost:3000/data');
};
factory.getFullData = function(q) {
return $http.get('http://localhost:3000/edit?qname='+q);
};
return factory;
});
</script></body>
On the express side I have 在快递方面,我有
app.get '/qname.html', (req, res) ->
res.sendfile 'qname.html'
app.get '/editor.html', (req, res) ->
res.sendfile 'editor.html'
and http://localhost:3000/qname.html
returns the content (below) of the file seemingly correctly 和http://localhost:3000/qname.html
看似正确地返回文件的内容(如下)
<section class="container">
<label>search qName:</label>
<input type="text" ng-model="searchname" placeholder="Enter a name here">
<div ng-repeat="qname in qnames | filter: searchname | orderBy: 'date':true"> <!-- Newest first -->
<a href="/edit?qname={{qname.qname}}">{{qname.rname}}</a>
</div>
</section>
Check the spelling of templateURL
: it should be spelled with a lower-case r and l, ie, templateUrl
. 检查templateURL
的拼写:应该使用小写的r和l拼写,即templateUrl
。 See: the $routeProvider
documentation 请参阅: $routeProvider
文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.