AngularJS - 无法读取属性'航行'未定义 [英] AngularJS - Cannot read property 'navigable' of undefined

查看:394
本文介绍了AngularJS - 无法读取属性'航行'未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的app.run:

app.run([
'$q', '$rootScope', '$state', 'settings', 'datacontext',
function ($q, $rootScope, $state, settings, datacontext) {
    settings.currentLang = settings.languages[0];
    breeze.core.extendQ($rootScope, $q);
    datacontext.getSideMenuItems().then(function (data) {
        var startUp = undefined;
        var rootUrl = '/app/views/';

        /// this is the upper level used for side menu only
        angular.forEach(data, function (value) {  
            // now loop thru the data for the $state items
            angular.forEach(value.viewStates, function (viewState, key) {

            if (key == 0) {
                startUp = viewState.name;
            }

            var state = {
                "url": '/' + viewState.name,
                "parent": viewState.parentName,
                "abstract": viewState.isAbstract,
                "views": {}
            };

            angular.forEach(viewState.views, function (view) {
                state.views[view.name] = {
                    controller: view.controllerName,
                    templateUrl: rootUrl + view.templateUrl + '.html'
                };
            });

            $stateProviderRef.state(viewState.name, state);
        });
        $state.go(startUp);
        });
    });
}

我的数据:[为JSON重新presentation,忽略了资本,微风重命名他们小写]

[{
"$id": "1",
"Id": 2,
"Icon": "fa-home",
"IsActive": "active",
"IsShared": false,
"OrderNum": 1000,
"Title": "Dashboards",
"FK_DbModuleId": 1,
"DBoardModule": null,
"ViewStates": [
    {
        "$id": "2",
        "Id": 2,
        "IsAbstract": false,
        "Name": "PersDboards01",
        "ParentName": "root",
        "OrderNum": 1,
        "FK_ViewGroupId": 2,
        "ViewGroup": {
            "$ref": "1"
        },
        "Views": [
            {
                "$id": "3",
                "Id": 4,
                "ControllerName": "MyDashboardCtrl",
                "Name": "container@",
                "TemplateUrl": "dashboards/myDashboard",
                "FK_ViewStateId": 2,
                "ViewState": {
                    "$ref": "2"
                }
            },
            {
                "$id": "4",
                "Id": 5,
                "ControllerName": "LeftPanelCtrl",
                "Name": "leftPanel@",
                "Title": "null",
                "TemplateUrl": "shell/html/left-panel",
                "FK_ViewStateId": 2,
                "ViewState": {
                    "$ref": "2"
                }
            }
        ]
    }
] 

我知道JSON有性质资本,但我没有真正使用JSON,我刚才复制这一关提琴手它得到它从我的Web API的。

据我所知,错误无法读取属性未定义的'航行'的意思我不定义子状态后,我定义了父母的状态,但我不能看到我这样做。

I understand that the error "Cannot read property 'navigable' of undefined" means I am not defining the child state after I define the parent state, but I cannot see where I am doing that.

有谁知道一个更好的方式来构造app.run?

Does anyone know a better way to structure the app.run?

更新:

我发现我的错误,见下文。

I found my error, see below.

推荐答案

解决:

事实上,错误是由于我的孩子创造的状态。

Indeed the error was due to my creating child states before establishing the parent state.

我看了看我的数据库,发现父状态过去在我的阙:

I looked at my database and noticed the parent state LAST in my que:

编号:150结果
IsAbstract:1结果
产品名称:根结果
ParentName:结果
 .....

Id : 150
IsAbstract : 1
Name: "root"
ParentName: ""
.....

如果我确信,使其首先这个问题就不会发生。

Had I made sure to make it first the problem would not have occured.

ID:1结果
IsAbstract:1结果
产品名称:根结果
ParentName:结果
 .....

Id : 1
IsAbstract : 1
Name: "root"
ParentName: ""
.....

我承认这种情况不会帮助许多其他不是作为一个提醒,以确保您的父状态是第一状态在循环创建动态的状态/视图时

I recognize this situation will not help many other than as a reminder to make sure your parent state is the first state in your loop when creating dynamic states/views

这篇关于AngularJS - 无法读取属性'航行'未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆