[英]angularjs: ui-router (nested view) and bootstrap tabs not playing nice
http://plnkr.co/edit/F5jojPEBVaAIyMa0CXDw http://plnkr.co/edit/F5jojPEBVaAIyMa0CXDw
I am having issues getting the ui-router to load a fragment into a bootstrap tab body. 我在让ui-router将片段加载到引导标签主体时遇到问题。 I linked my code example above.
我链接了上面的代码示例。 Please let me know if I missed something.
如果我错过了什么,请告诉我。 I have looked at 10 different stack overflow examples and non of them have helped solve my problem.
我已经看了10个不同的堆栈溢出示例,其中没有一个帮助解决了我的问题。
I have an outer ui-view that loads the initial page fragment fine. 我有一个外部ui视图,可以很好地加载初始页面片段。
<div id="view" ui-view></div>
Next I have the fragment that is loaded (This is where the tabs are set up) 接下来我有加载的片段(这是设置选项卡的位置)
<div class="row">
<div class="col-lg-10 col-lg-offset-1">
<ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
<li ng-repeat="tab in tabs" ui-sref="{{tab.link}}" ui-sref-active="active"><a>{{tab.label}}</a></li>
</ul>
<div id="my-tab-content" class="tab-content" ui-view="tabs"></div>
</div>
</div>
Following that I have a two fragment pages that for test only have some text in them (request-tab.html and approved-tab.html) 接下来我有一个两个片段页面,测试只有一些文本(request-tab.html和approved-tab.html)
Finally, I have the js file that routes the views. 最后,我有路由视图的js文件。 I left off the controllers to shorten the post.
我离开控制器以缩短帖子。 They are on the plunker if needed but they shouldn't be the issue.
如果需要的话,他们就是掠夺者,但他们不应该成为问题。
var app = angular.module("BRAVO", ['ui.router', 'ui.bootstrap', 'ui.bootstrap.tpls']);
app.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/requestView/request');
$stateProvider
/* Main Views */
.state('requestView', {
url: '/requestView',
templateUrl: 'bravo_home.html',
controller: 'requestCtrl'
})
/*Other states here*/
/* Tabs */
.state('requestView.request', {
url: '/request',
view: {
'tabs': {
templateUrl: 'request-tab.html',
controller: 'requestTabCtrl'
}
}
})
.state('requestView.approved', {
url: '/approved',
view: {
'tabs': {
templateUrl: 'approved-tab.html'
}
}
});
})
<div class="row"> <div class="col-lg-10 col-lg-offset-1"> <ul id="tabs" class="nav nav-tabs" data-tabs="tabs"> <li ui-sref-active="active" ng-repeat="tab in tabs"><a ui-sref="{{tab.link}}" >{{tab.label}}</a></li> </ul> <div id="my-tab-content" class="tab-content" ui-view="tabs"></div> </div> </div>
You should set your states like this: 你应该像这样设置你的状态:
$stateProvider
/* Main Views */
.state('requestView', {
url: '/requestView',
templateUrl: 'bravo_home.html',
controller: 'requestCtrl'
})
/*Other states here*/
/* Tabs */
.state('requestView.request', {
url: '/request',
templateUrl: 'request-tab.html'
})
.state('requestView.approved', {
url: '/approved',
templateUrl: 'approved-tab.html'
});
Then, in your bravo_home.html: <div id="my-tab-content" class="tab-content" ui-view></div>
Note that I removed the ="tabs". 然后,在你的bravo_home.html:
<div id="my-tab-content" class="tab-content" ui-view></div>
请注意,我删除了=“tabs”。 You can add controllers to your nested tab states as needed, for example: 您可以根据需要将控制器添加到嵌套选项卡状态,例如:
// add "controller: 'requestTabCtrl'" to state
.controller("requestTabCtrl", function($scope) {
console.log('Hello Request Tab');
})
// add "controller: 'approvedTabCtrl''" to state
.controller("approvedTabCtrl", function($scope) {
console.log('Hello Approved Tab');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.