我开始使用AngularJS v1.4.0测试新的ui-router v1.0.0alpha0,但出现此错误:
TypeError: Cannot read property 'creationContext' of undefined
at http://localhost:1828/lib/angular-ui-router/release/angular-ui-router.js:1573:65
at curried (http://localhost:1828/lib/angular-ui-router/release/angular-ui-router.js:128:24)
at http://localhost:1828/lib/angular-ui-router/release/angular-ui-router.js:130:21
at Array.filter (native)
at matchingConfigPair (http://localhost:1828/lib/angular-ui-router/release/angular-ui-router.js:1587:48)
at Array.map (native)
at $View.sync (http://localhost:1828/lib/angular-ui-router/release/angular-ui-router.js:1597:53)
at $View.register [as registerUiView] (http://localhost:1828/lib/angular-ui-router/release/angular-ui-router.js:1605:15)
at http://localhost:1828/lib/angular-ui-router/release/angular-ui-router.js:3741:37
at invokeLinkFn (http://localhost:1828/lib/angular/angular.js:8604:9) <!-- uiView: subjects.intro -->
这是我的app.config:
var home = {
name: 'home',
template: '<div data-ui-view></div>',
url: '/home/'
};
var homeSubjects = {
name: 'home.subjects',
resolve: {
getSubjects: ['subjectService',
(sus: ISubjectService) => {
console.log("getSubjects");
sus.getSubjects();
return true;
}]
},
url: 'subjects',
views: {
'': {
templateUrl: 'app/subjects/partials/subjects.html',
},
'subjects.intro@home.subjects': {
templateUrl: 'app/subjects/partials/subjects_intro.html',
},
'subjects.auth@home.subjects': {
templateUrl: 'app/subjects/partials/subjects_auth.html',
}
}
};
有谁知道是什么原因可能导致此问题,或者我如何继续查找有关我在路由器0.2版本中未遇到的问题的更多信息?
谢谢
最佳答案
您遇到此错误是因为它试图查找名为ui-view
的subjects
作为父对象。
Imo只需执行以下操作即可:
'intro@home.subjects': {
在
'info'
的上下文中绝对定位'home.details'
View 。因此,您可以在
app/subjects/partials/subjects.html
中拥有以下ui View :<div ui-view='intro'/>
但是,如果您要来执行,则希望
ui-view
名称中的点应从ui-router
source中读取此注释。 /*
* If the ViewConfig's target ui-view name is a segmented name (with dots), then a ui-view matches if:
* - There exists a parent ui-view where:
* - the parent ui-view's name matches the first segment (index 0) of the ViewConfig's target name
* - the parent ui-view's context matches the ViewConfig's anchor
* - And the remaining segments (index 1..n) of the ViewConfig's target name match the tail of the ui-view's fqn
*/
因此,在您的情况下,我想这适用:
'$default.intro@home.subjects': {
关于angularjs - ui路由器v1.0.0alpha0-TypeError : Cannot read property 'creationContext' of undefined,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35220208/