我开始用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 -->
Run Code Online (Sandbox Code Playgroud)
这是我的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',
}
}
};
Run Code Online (Sandbox Code Playgroud)
有没有人知道是什么原因可能导致这个问题,或者我怎么能继续找到更多关于我在0.2版本的路由器中没有得到的问题?
谢谢
您遇到此错误是因为它尝试查找ui-view指定subjects的父级。
在我看来,这样做更简单:
'intro@home.subjects': {
Run Code Online (Sandbox Code Playgroud)
绝对针对'info'的背景下的视图'home.details'。
所以你可以在其中拥有以下 ui-view app/subjects/partials/subjects.html:
<div ui-view='intro'/>
Run Code Online (Sandbox Code Playgroud)
但是,如果您确实希望名称中包含点,请阅读来源ui-view中的此评论。ui-router
/*
* 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
*/
Run Code Online (Sandbox Code Playgroud)
所以在你的情况下我想这适用:
'$default.intro@home.subjects': {
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
564 次 |
| 最近记录: |