UI路由器状态的多个视图不起作用.未报告错误
multiple views in ui-router state not working .. no errors reported
嗨,我正在处理一个单一状态的多个嵌套视图,就像在这个 plunkr[http://plnkr.co/edit/FKdwViJllUKGoYIAWIED?p=preview] 中一样,但它不起作用,而且我没有事件得到任何错误。有点完全卡住了任何帮助,非常感谢。我的配置块如下
.config(function($stateProvider,$urlRouterProvider){
$stateProvider.
state('home',{
url: '/',
views: {
'funeralhomes': {
templateUrl: './funeralhome.tpl.html',
controller: 'FuneralCtrl',
resolve: {
funeralhomes : ['FuneralHomes',function(FuneralHomes){
return FuneralHomes.list;
}]
}
},
'caskets':{
templateUrl: './casket.tpl.html',
controller: 'CasketCtrl',
resolve:{
caskets: ['Caskets',function(Caskets){
return Caskets.list;
}]
}
},
'foods':{
templateUrl: './food.tpl.html',
controller: 'FoodCtrl',
resolve: {
foods: ['Foods',function(Food){
return Food.list;
}]
}
},
'officiants':{
templateUrl: './officiant.tpl.html',
controller: 'OfficiantCtrl',
resolve: {
officiants: ['Officiants',function(Officiants){
return Officiants.list;
}]
}
},
'flowers':{
templateUrl: './flower.tpl.html',
controller: 'FlowersCtrl',
resolve: {
flowers: ['Flowers',function(Flowers){
return Flowers.list;
}]
}
},
'donations':{
templateUrl: './donation.tpl.html',
controller: 'DonationsCtrl',
resolve: {
donations: ["Donations",function(Donations){
return Donations.list;
}]
}
},
'monuments':{
templateUrl: './monument.tpl.html',
controller: 'MonumentCtrl',
resolve: {
monuments: ['Monuments',function(Monuments){
return Monuments.list;
}]
}
}
},
abstract: true,
controller: 'HomeCtrl'
})
.state('home.login',{
templateUrl: './login.tpl.html',
controller: 'LoginCtrl'
});
$urlRouterProvider.otherwise('home');
})
不完全确定您要实现的目标,但我更新了您的 plunker 以使其运行(只是运行)
我首先使用了这个说法:
// instead of this - state name
// $urlRouterProvider.otherwise('home');
// we have to use url
$urlRouterProvider.otherwise('/');
原因?我们必须传递状态 URL,而不是它的名称
此外,主状态是抽象的,因此我们需要导航到某个不是的状态。 这将是子级,其 URL 必须与其他状态匹配。正如 doc 所说,我们可以这样做:
.state('home.login',{
// new line - the otherwise is in fact also matching this non abstract state
url : '',
templateUrl: './login.tpl.html',
controller: 'LoginCtrl'
});
看:
如何:设置默认/索引子状态
为"parent.index"状态提供一个空网址。这将使它与父状态 url 匹配相同的 url,因为它不会向父 url 追加任何内容。
$stateProvider
.state('parent', {url: '/home', abstract: true, template: '<ui-view/>'} )
// ALSO url '/home', overriding its parent's activation
.state('parent.index', {url: ''} )
在此处查看更新的 plunker
您的代码段不起作用,因为您在家乡的状态下将抽象设置为 true:
},
abstract: true, // remove this
controller: 'HomeCtrl'
})
.state('home.login',{
templateUrl: './login.tpl.html',
controller: 'LoginCtrl'
将抽象设置为 true 会使状态不可激活。从文档中:
抽象状态可以有子状态,但不能被激活 本身。"抽象"状态只是一种不可能的状态 过渡到。当它的一个隐式激活时 后代被激活。
参考: https://github.com/angular-ui/ui-router/wiki/Nested-States-%26-Nested-Views
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- 监视函数从服务返回不起作用,但作用域函数起作用
- 幻灯片滚动javascript不起作用
- 简单的javascript在Shopify中不起作用
- Recaptcha在IE7和IE8中不起作用
- Ember Data DS.Model's set函数不起作用
- JsFiddle上的鼠标事件不起作用
- 我的AngularJS表达式没有'不起作用
- 点击按钮输入不起作用
- 面向对象的Javascript代码在IE7中不起作用
- 分部隐藏在jquery中不起作用
- 在phonegap应用程序内部重定向不起作用
- Array.length似乎不起作用;console.log则显示其他情况
- $ionicplatform内的$scope不;不起作用
- 我的javascript for循环不起作用
- Meteor-添加用户自定义字段的方法不起作用
- 为什么 .focus() 不起作用,而 .css(“color”,“red”) 在同一个选择器上起作用
- Textarea必需的attribut在javascript中不起作用
- UI路由器状态的多个视图不起作用.未报告错误
- 我的报告创建的php表单验证不起作用