Angular ui-查看默认/正确用法:
Angular ui-view default / proper usage:
这是我主视图的 'subset' 视图,我有一个标签栏(地图、市场和图表)。单击它们时,它们会通过 UiSref 在该标签中正确输出。
<div ui-view name="inception2"></div>
这 3 个视图在我的路由文件中定义,如下所示。
如何将 uiViewName 中的视图默认为 tsView2?目前我需要点击才能路由。我再次设置了一个路由器文件,它确实具有抽象状态和所有 - 这仅适用于现有项目中的简单选项卡练习。谢谢!
.state('tsView1', {
views: {
'inception2': {
templateUrl: 'client/templates/tsVview1.html'
}
}
})
.state('tsView2', {
views: {
'inception2': {
templateUrl: 'client/templates/tsView2.html'
}
}
})
.state('tsView3', {
views: {
'inception2': {
templateUrl: 'client/templates/tsView3'
}
}
})
使用$urlRouterProvider
使用otherwise
方式配置默认路由
.state('tsView2', {
url: '/tsview2',
views: {
'inception2': {
templateUrl: 'client/templates/tsView2.html'
}
}
})
$urlRouterProvider.otherwise('/tsview2');
有关 $urlRouterProvider
的详细信息,请参阅:https://github.com/angular-ui/ui-router/wiki/URL-Routing#urlrouterprovider
您可以试试这个解决方案
引入一个小引擎,读取一个设置redirectTo
app.run(['$rootScope', '$state', function($rootScope, $state) {
$rootScope.$on('$stateChangeStart', function(evt, to, params) {
if (to.redirectTo) {
evt.preventDefault();
$state.go(to.redirectTo, params)
}
});
}]);
然后在其 parent
上应用默认 child
.state('main', {
redirectTo: 'tsView2',
...
}
.state('tsView2', {
parent: 'main'
...
}
换句话说,这要求 tsViews 是子视图...但我想它已经应该是真的了
This is for a 'subset' view off of my main view where I have...
这是我主视图的 'subset' 视图,我有一个标签栏(地图、市场和图表)。单击它们时,它们会通过 UiSref 在该标签中正确输出。
<div ui-view name="inception2"></div>
这 3 个视图在我的路由文件中定义,如下所示。
如何将 uiViewName 中的视图默认为 tsView2?目前我需要点击才能路由。我再次设置了一个路由器文件,它确实具有抽象状态和所有 - 这仅适用于现有项目中的简单选项卡练习。谢谢!
.state('tsView1', {
views: {
'inception2': {
templateUrl: 'client/templates/tsVview1.html'
}
}
})
.state('tsView2', {
views: {
'inception2': {
templateUrl: 'client/templates/tsView2.html'
}
}
})
.state('tsView3', {
views: {
'inception2': {
templateUrl: 'client/templates/tsView3'
}
}
})
使用$urlRouterProvider
使用otherwise
方式配置默认路由
.state('tsView2', {
url: '/tsview2',
views: {
'inception2': {
templateUrl: 'client/templates/tsView2.html'
}
}
})
$urlRouterProvider.otherwise('/tsview2');
有关 $urlRouterProvider
的详细信息,请参阅:https://github.com/angular-ui/ui-router/wiki/URL-Routing#urlrouterprovider
您可以试试这个解决方案
引入一个小引擎,读取一个设置redirectTo
app.run(['$rootScope', '$state', function($rootScope, $state) {
$rootScope.$on('$stateChangeStart', function(evt, to, params) {
if (to.redirectTo) {
evt.preventDefault();
$state.go(to.redirectTo, params)
}
});
}]);
然后在其 parent
上应用默认 child.state('main', {
redirectTo: 'tsView2',
...
}
.state('tsView2', {
parent: 'main'
...
}
换句话说,这要求 tsViews 是子视图...但我想它已经应该是真的了
This is for a 'subset' view off of my main view where I have...