简体   繁体   English

AngularJS ui-router中的Bootstrap UI选项卡

[英]Bootstrap UI Tabs in AngularJS ui-router

I have some problem with Bootstrap UI Tabs in AngularJS ui-router. 我在AngularJS ui-router中的Bootstrap UI选项卡上遇到一些问题。 I want to add active class when refresh the page, so I send tab's URL into asActive(url) function, as parametr to my controller, where I compare that tab's URL with current URL of entire page. 我想在刷新页面时添加活动类,因此我将选项卡的URL发送到asActive(url)函数中,作为对我的控制器的参数,在此我将该选项卡的URL与整个页面的当前URL进行比较。 It works properly. 它正常工作。 I use " active " parametr of tab-directive, that is bindind with "=". 我使用制表符指令的“ active ”参数,即用“ =”绑定的indind。

When I refresh my page - everything is OK, but when I click on the tab pane I got an error in console. 当我刷新页面时-一切正常,但是当我单击选项卡窗格时,控制台出现错误。

Expression 'isActive('configuration.partnership-groups')' used with directive 'tab' is non-assignable!

So, my html: 因此,我的html:

<tabset justified="true">
    <tab heading="DV Group" ui-sref="configuration.dv-group" active="isActive('configuration.dv-group')">
        <div ui-view></div>
    </tab>
    <tab heading="Partneship group" ui-sref="configuration.partnership-groups" active="isActive('configuration.partnership-groups')">
        <div ui-view></div>
    </tab>
    <tab heading="Permissions" ui-sref="configuration.permissions" active="isActive('configuration.permissions')">
        <div ui-view></div>
    </tab>
</tabset>

And my controller: 而我的控制器:

$scope.isActive = function (state) {
    return angular.equals(state, $state.$current.name);
};

Anybody knows solution of this issue? 有人知道这个问题的解决方案吗? Thanks in advance. 提前致谢。

You should check this link on non assign. 您应在未分配时检查链接。 Basically, you need to have something passed in that can be assigned a value, and not something that is a value. 基本上,您需要传入的内容可以分配一个值,而不是一个值。 You can't reassign true or false. 您不能重新分配是非。 Try this 尝试这个

Try injecting the tab data through your state resolve 尝试通过状态解析注入选项卡数据

$stateProvider
    .state('configuration.dv-group', {
        // your state stuff
        resolve: {
            tabs: {
                tabs = function() {
                    var tabData = [{ active: true }, { active: false }, { active: false }] 
                    return tabData;
                }
        }
    })
    .state(...)

where the other states are defined similarly. 其他状态的定义类似。

Change your html to be 将您的html更改为

<tabset justified="true">
    <tab heading="DV Group" ui-sref="configuration.dv-group" active="tabs[0].active">
        <div ui-view></div>
    </tab>
    <tab heading="Partneship group" ui-sref="configuration.partnership-groups" active="tabs[1].active">
        <div ui-view></div>
    </tab>
    <tab heading="Permissions" ui-sref="configuration.permissions" active="tabs[2].active">
        <div ui-view></div>
    </tab>
</tabset>

and inject the resolve into your controller: 并将解决方案注入您的控制器:

angular.module('yourapp')
    .controller('YourController', ['$scope', 'tabs', function($scope, tabs) {
       $scope.tabs = tabs;
    });

With this you can also use ng-repeat and populate tab data in the resolve based on the state if you want. 这样,您还可以根据需要使用ng-repeat并根据状态在选项卡中填充标签数据。 This matches very similarly the example in the documentation for tab. 这与选项卡文档中的示例非常相似。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM