我遇到一個問題,(我認爲)與UI的路由器v0.4.2拋出下面的錯誤,當我嘗試運行$state.go();
14:57:22.563 Error: [$http:badreq] Http request configuration url must be a string. Received: ["$stateParams",null] http://errors.angularjs.org/1.5.8/ $http/badreq?p0=%5B%22%24stateParams%22%2Cnull%5D Stack trace: minErr/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:68:12 [email protected]http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:11439:15 createShortMethods/http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:11698:18 [email protected]http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:19419:14 TemplateFactory/[email protected]http://localhost:3001/vendor.js:1488:16 TemplateFactory/[email protected]http://localhost:3001/vendor.js:1444:39 [email protected]http://localhost:3001/vendor.js:4586:20 resolveViews/http://localhost:3001/vendor.js:4479:20 [email protected]http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:4718:16 [email protected]http://localhost:3001/vendor.js:1266:32 [email protected]http://localhost:3001/vendor.js:1262:26 $Resolve/this.study/<@http://localhost:3001/vendor.js:1241:14 $Resolve/[email protected]http://localhost:3001/vendor.js:1345:12 resolveViews/<@http://localhost:3001/vendor.js:4482:30 [email protected]http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:335:11 [email protected]http://localhost:3001/vendor.js:4476:9 [email protected]http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:16383:28 scheduleProcessQueue/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:16399:27 $RootScopeProvider/this.$gethttp://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:17682:16 $RootScopeProvider/this.$gethttp://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:17495:15 $RootScopeProvider/this.$gethttp://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:17790:13 ngEventHandler/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:25890:17 [email protected]http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:3497:3 createEventHandler/[email protected]http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:3485:9 1 script.js:1301:13 http://localhost:3001/app/script.js:1301:13 $RootScopeProvider/this.$gethttp://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:18005:15 transitionTo/$state.transition< http://localhost:3001/vendor.js:4245:15 processQueue http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:16383:28 scheduleProcessQueue/< http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:16399:27 $RootScopeProvider/this.$gethttp://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:17682:16 $RootScopeProvider/this.$gethttp://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:17495:15 $RootScopeProvider/this.$gethttp://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:17790:13 ngEventHandler/< http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:25890:17 defaultHandlerWrapper http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:3497:3 createEventHandler/eventHandler http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js:3485:9
的路線是這樣的:
.state('foo.bar', {
url: '/:type/:id',
views: {
'question': {
templateUrl: ['$stateParams', function (stateParams) {
var qID = stateParams.id;
var template = qID + '.tmpl.html';
var url = "app/section/foo/";
return qID <= 7 ? url + 'general/' + template : url + stateParams.type + "/" + template;
}]
}
}
})
而且我用這個來嘗試並進入狀態:
$state.go('foo.bar', {
type: 'typeA',
id: 1
});