javascript – Angularjs ui-router没有到达子控制器
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – Angularjs ui-router没有到达子控制器,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3218字,纯文字阅读大概需要5分钟。
内容图文
我有一个配置功能:
function config($stateProvider,$locationProvider) {
$locationProvider.html5Mode(true);
$stateProvider
.state('projectsWs.tasks', {
url: "/tasks",
views: {
"mainView": {
templateUrl: "/app/projects/templates/index.php"
},
"innerView": {
templateUrl: "/app/projects/templates/tasks.php",
controller: tasksCtrl,
controllerAs:'tasks'
}
}
})
.state('projectsWs.tasks.detail', {
url: "/:taskId",
views: {
"mainView@": {
templateUrl: "/app/projects/templates/index.php"
},
"innerView@mainView": {
templateUrl: "/app/projects/templates/tasks.php",
controller: function($stateParams) {
console.log('innerViewCtrl', $stateParams);
}
}
}
});}
InnerView位于mainView中.
当我有/ project-ws / tasks之类的url时,tasksCtrl函数按预期工作.但是当我有一个带有id的url,即/ projects-ws / tasks / 32时,我看不到任何输出,但我希望innerViewCtrl输出,这就是我得到的问题.我认为我的绝对/相对观点存在问题,但我已经尝试了所有组合,但仍然无效.
更新:
所以现在我有以下状态:
state('projectsWs.tasks.detail', {
url: "/:taskId",
views: {
"mainView@": {
templateUrl: "/app/projects/templates/index.php",
controller: function($stateParams) {
console.log('mainViewctrl', $stateParams);
}
},
"innerView": {
templateUrl: "/app/projects/templates/tasks.php",
controller: function($stateParams) {
console.log('innerViewctrl', $stateParams);
}
}
}
})
正如RadimKöhler所说.它输出mainViewctrl Object {taskId:“32”},但是如何从innerView到达$stateParams.taskId呢?
解决方法:
UI-Router的绝对命名与您使用它有点不同
.state('projectsWs.tasks.detail', {
url: "/:taskId",
views: {
"mainView@": {
templateUrl: "/app/projects/templates/index.php"
},
// this won't work, because the part after @
// must be state name
"innerView@mainView": {
// so we would need this to target root, index.html
"innerView@": {
// or this to target nested view inside of a parent
"innerView": {
// which is the same as this
"innerView@projectsWs.tasks": {
检查:
View Names – Relative vs. Absolute Names
小引用:
Behind the scenes, every view gets assigned an absolute name that follows a scheme of
viewname@statename
, where viewname is the name used in the view directive and state name is the state’s absolute name, e.g. contact.item. You can also choose to write your view names in the absolute syntax.
我创建了一个working example here,状态是这样的
$stateProvider
.state('projectsWs', {
template: '<div ui-view="mainView" ></div>' +
'<div ui-view="innerView" ></div>',
})
$stateProvider
.state('projectsWs.tasks', {
url: "/tasks",
views: {
"mainView": {
//templateUrl: "/app/projects/templates/index.php"
template: "<div>main view tasks </div>",
},
"innerView": {
//templateUrl: "/app/projects/templates/tasks.php",
template: "<div>inner view tasks </div>",
}
}
})
.state('projectsWs.tasks.detail', {
url: "/:taskId",
views: {
"mainView@projectsWs": {
//templateUrl: "/app/projects/templates/index.php"
template: "<div>main view task {{$stateParams | json }} </div>",
},
"innerView@projectsWs": {
//templateUrl: "/app/projects/templates/tasks.php",
template: "<div>inner view task {{$stateParams | json }} </div>",
}
}
});
我们可以看到,祖父项目Ws正在注入index.html(root)< div ui-view =“”>一些模板,有两个命名锚点:
template: '<div ui-view="mainView" ></div>' +
'<div ui-view="innerView" ></div>',
然后将其用于列表和详细信息状态,以及相对resp绝对名称
检查它here在行动
内容总结
以上是互联网集市为您收集整理的javascript – Angularjs ui-router没有到达子控制器全部内容,希望文章能够帮你解决javascript – Angularjs ui-router没有到达子控制器所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。