[英]First angular app not loading routes
我一直在嘗試跟蹤Dan Wahlin的YT視頻,並使用我自己的數據以並行方式實現它。 后端在express和mongo中,下面的代碼工作到我開始添加路由為止。 鏈接到的兩個文件存在,並且所有文件都在服務器上運行,這排除了類似發帖人的問題,但是未加載部分文件(我看到一些跡象表明ng-view存根已被角度更改,但未注入新內容)。 有什么線索嗎?
<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>
在快遞方面,我有
app.get '/qname.html', (req, res) ->
res.sendfile 'qname.html'
app.get '/editor.html', (req, res) ->
res.sendfile 'editor.html'
和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>
檢查templateURL
的拼寫:應該使用小寫的r和l拼寫,即templateUrl
。 請參閱: $routeProvider
文檔
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.