错误:无法从状态'index'解析'storysolo'

时间:2015-09-17 17:21:02

标签: javascript angularjs state angular-ui-router

我的index.php页面带有ui-sref链接,如下所示

 <a ui-sref="storysolo({ storyId: headline.nid })">  

我的主js文件加载角度代码如下

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链接时,我收到此错误

  

无法解决州'索引'的'storysolo'

我加载的文件顺序如下

  • angular.js,
  • 角sanitize.js,
  • 角-UI-router.js,
  • rebelFleet.js,(主要的js文件)
  • story.js

我猜我在加载路由的方式上做错了,UI-Router讨厌它。任何帮助将非常感激。

1 个答案:

答案 0 :(得分:1)

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