AngularJS - 无法读取未定义的属性“可导航" [英] AngularJS - Cannot read property 'navigable' of undefined
问题描述
我的 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 表示,忽略大写,微风将它们重命名为小写]
[{
"$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 中获取的 fiddler 复制了它.
我知道错误无法读取未定义的属性 'navigable'"意味着我在定义父状态后没有定义子状态,但我看不到我在做什么.
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.
我查看了我的数据库并注意到我的队列中的父状态 LAST:
I looked at my database and noticed the parent state LAST in my que:
ID:150
IsAbstract : 1
名称:根"
父名称:""
.....
Id : 150
IsAbstract : 1
Name: "root"
ParentName: ""
.....
如果我确保首先做到这一点,问题就不会发生.
Had I made sure to make it first the problem would not have occured.
编号:1
IsAbstract : 1
名称:根"
父名称:""
.....
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屋!