我的 index.php 页面带有 ui-sref 链接,如下所示
<a ui-sref="storysolo({ storyId: headline.nid })">
我的主 js 文件加载 Angular 代码如下
var rebelFleet = angular.module("CougsApp", ["ui.router","ngAnimate", "ui.bootstrap", "ngSanitize", "slick","CougsApp.headlines","CougsApp.story","CougsApp.recentstories" ]);
rebelFleet.config(function($stateProvider) {
// For any unmatched url, redirect to /state1
$stateProvider
.state('index', {
url: "",
views: {
"navViewPort": { templateUrl: '/components/nav/nav.html'
},
"contentViewPort": {
templateUrl: '/components/headlines/headlines.html',
controller: "headlinesCtrl"
},
"eventsViewPort": { templateUrl: '/components/scroller/scroller.html' },
"bottomContentViewPort": { templateUrl: '/components/recentstories/recentstories.html',
controller: "recentstoriesCtrl"
},
"rightsideViewPort": { templateUrl: '/components/social/social.html' },
"footerViewPort": { templateUrl: '/components/footer/footer.html' }
}
})
然后我的story.js 文件尝试使用它自己的路由加载。如下
var ywing = angular.module('CougsApp.story', ["ui.router"]);
ywing.config(function($stateProvider, $urlRouterProvider) {
$stateProvider.state('storySolo', {
url: '/story/:storyId',
views: {
"navViewPort": { templateUrl: '/components/nav/nav.html'
},
"contentViewPort": {
templateUrl: '/components/story/story.html',
controller: "storyCtrl"
},
"footerViewPort": { templateUrl: '/components/footer/footer.html' }
}
})
});
因此,当我加载页面并单击 ui-sref 链接时,我收到此错误
Could not resolve 'storysolo' from state 'index'
我的文件加载顺序如下
- Angular.js,
- Angular-sanitize.js,
- Angular-ui-router.js,
- rebelFleet.js,(主js文件)
- 故事.js
我猜我在加载路由的方式上做错了什么,并且 UI-Router 讨厌它。任何帮助将非常感激。
最佳答案
不管你信不信,这很简单——它是区分大小写的。状态名称必须符合 1) 定义以及 2) 调用方
// small solo
<a ui-sref="storysolo({ storyId: headline.nid })">
// capitalized Solo
$stateProvider.state('storySolo', {...
所以只需使用其中之一,例如:
// not small solo
<a ui-sref="storySolo({ storyId: headline.nid })">
// the same name here
$stateProvider.state('storySolo', {...
关于javascript - 错误: Could not resolve 'storysolo' from state 'index' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32636337/