使用MeteorJS在AngularJS上完成此tutorial,但是遇到了ui.router,$ stateProvider和$ locationProvider的一些问题。
我的问题是,就我所知,所有内容都应该正确连接以进行路由,但我的链接实际上并不起作用。我的主要文件的内容如下,但有关该问题的更多信息:
问题似乎在于//$locationProvider.html5mode(true)行;在app.js.它目前被注释掉,它允许页面加载,但不能正确地路由链接。如果我取消注释,则页面返回以下错误:
Uncaught Error: [$injector:modulerr] Failed to instantiate module socially due to:
TypeError: undefined is not a function
我假设参考$ locationProvider未定义。这看起来很像依赖注入错误,但我找不到任何依赖注入错误。任何帮助非常感谢。
app.js
if (Meteor.isClient){
angular.module("socially", ['angular-meteor', 'ui.router']);
angular.module("socially").config(['$urlRouterProvider', '$stateProvider', '$locationProvider', function($urlRouterProvider, $stateProvider, $locationProvider) {
$stateProvider
.state('parties', {
url: '/parties',
templateUrl: 'parties-list.ng.html',
controller: 'PartiesListCtrl'
})
.state('partyDetails', {
url: '/parties/:partyId',
templateUrl: 'party-details.ng.html',
controller: 'PartyDetailsCtrl'
});
$urlRouterProvider.otherwise('/parties');
//$locationProvider.html5mode(true);
}]);
angular.module("socially").controller("PartiesListCtrl", ['$scope', '$meteor', function($scope, $meteor){
$scope.parties = $meteor.collection(Parties);
$scope.remove = function(party){
$scope.parties.remove(party);
};
$scope.removeAll = function(){
$scope.parties.remove();
};
}]);
angular.module("socially").controller('PartyDetailsCtrl', ['$scope', '$stateParams', function($scope, $stateParams){
$scope.partyId = $stateParams.partyId;
}]);
}
的index.html
<head>
<base href="/">
</head>
<body>
<div ng-app="socially">
<h1>
<a href="/parties">Home</a>
</h1>
<div ui-view></div>
</div>
</body>
方-list.ng.html
<form>
<label>Name</label>
<input ng-model="newParty.name">
<label>Description</label>
<input ng-model="newParty.desc">
<button ng-click="parties.push(newParty)">Add</button>
</form>
<ul>
<li ng-repeat="party in parties">
<a href="/parties/{{party._id}}">{{party.name}}</a>
<p>{{party.desc}}</p>
<p>{{party.name}}</p>
<button ng-click="remove(party)">X</button>
</li>
</ul>
党details.ng.html
Here you will see the details of party number: {{ partyId }}
答案 0 :(得分:2)
我最近也开始使用meteor-angular。 经过测试 - 看起来你的问题是一个简单的小写&#39; m。 我可以看到&#39; 5&#39;可能会使骆驼案件混乱。
更正:$locationProvider.html5Mode(true);