javascript - 错误: Could not resolve 'storysolo' from state 'index'

标签 javascript angularjs state angular-ui-router

我的 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 讨厌它。任何帮助将非常感激。

最佳答案

a working example

不管你信不信,这很简单——它是区分大小写的。状态名称必须符合 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', {...

检查example here

关于javascript - 错误: Could not resolve 'storysolo' from state 'index' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32636337/

相关文章:

javascript - 在 Bootstrap 和 AngularJS 中使用 ng-repeat 的结构问题

javascript - 另一个 transclude 指令中的 Angular transclude 指令

javascript - React Render Components with Loop,但是当状态更新时它会重新渲染所有内容

ajax - AngularJS 应用上的 DFP 广告

javascript - 迭代对象数组并将值相加

c# - 如何在 Windows 应用商店应用程序中保存我的状态?

android - 我可以使用 selector drawable 和 LinerLayout 来表示不同的状态吗?

javascript - 我想了解passport js如何工作,特别是req.user以及数据如何填充

javascript - React-router isActive 方法不起作用

javascript - AngularJS Select Multiple - 如何提交 id 而不是整个对象