简体   繁体   English

如何在angularjs中使用UI引导程序选项卡的内容动态地激活选项卡?

[英]how to Dynamically Active tab with content for ui bootstrap tabs in angularjs?

I want to dynamically active tab with content in angular js my code is 我想动态激活标签与角度js中的内容,我的代码是

<uib-tabset ng-if="pets_count > 0" class="petsTabs tab-animation">
    <div ng-repeat="(key, pet) in pets_list">
        <uib-tab heading="{{pet.pet_name}}" active="{{pet.pet_id == activePet}}">
            <div class="petsTabsContent" >
                <h4>
                    {{pet.pet_name}}
                    <small>
                        Boarding Dates: {{ pet.start_date | date : 'MMMM d, y'}} to {{ pet.end_date | date : 'MMMM d, y'}}
                    </small>
                </h4>
            </div>
        </uib-tab>
    </div>
</uib-tabset>

i have two variables pet.pet_id, activePet on base for these variables i have to active tab. 我有两个变量pet.pet_id,activePet这些变量的基础上我必须活动选项卡。 but it does not working i am new to angular js thanks in advance This controller 但是它不起作用我对angular js是陌生的,谢谢

$scope.show_pet_function = function () {
    var pet_id;
    var action;
    pet_id = parseInt($('.pet_view_option').attr('data-pet_id'));
    action = $('.pet_view_option').attr('data-action');
    petowner_user_id =  parseInt($('.pet_view_option').attr('data-pet-owner'));
    var details = $scope.hidePetData;
    $http.post(CONFIG.APIURL + 'Pets/changePetHideStatus/', {pet_id: pet_id, action: action})
            .then(function (response) {
                if (response.data.action == 'show_pet') {
                    promise = petlistFunction(petowner_user_id).then(function (response) {
                        $scope.activePet = pet_id;
                        angular.extend($scope.pets_list, response.data['pets_list']);
                    });
                    toastr.success(response.data.message);
                } else if (response.data.action == 'hide_pet') {
                    promise = petlistFunction(petowner_user_id).then(function (response) {
                        $scope.activePet = pet_id;
                        angular.extend($scope.pets_list, response.data['pets_list']);
                    });
                }
            });
}

This is response for pet_list object type array 这是对pet_list对象类型数组的响应 在此处输入图片说明

I think there might be an issue with $scope binding, as you are pulling the data in then-able function. 我认为$ scope绑定可能存在问题,因为您要在那时可用的函数中提取数据。 So try by placing $scope.$apply() after the $http response. 因此,请尝试在$ http响应后放置$scope.$apply() For reference add it like this 供参考,像这样添加

angular.extend($scope.pets_list, response.data['pets_list']);
$scope.$apply();

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

相关问题 angular ui bootstrap选项卡组件:未单击选项卡处于活动状态时如何获取选项卡内容 - angular ui bootstrap tabs component: how to get the content of a tab when the tab is active not clicked 使用Angular UI Bootstrap在动态创建的选项卡上设置活动选项卡 - Setting active tab on dynamically created tabs with Angular UI Bootstrap ui.bootstrap.tabs如何知道angularjs控制器中哪个选项卡处于活动状态 - ui.bootstrap.tabs how to know which tab is active in angularjs controller 默认情况下未加载angularjs引导ui活动选项卡 - angularjs bootstrap ui active tabs not loaded by default 如何在带有静态内容的angularjs引导选项卡上设置活动 - how to set active on angularjs bootstrap tab with static content 在带有静态内容的angularjs引导选项卡上处于活动状态 - Active on angularjs bootstrap tab with static content 在AngularUI引导程序中动态设置选项卡(ui.bootstrap.tabs) - Dynamically set tab in AngularUI Bootstrap (ui.bootstrap.tabs) Angularjs-ui bootstrap.tabs-添加下一个选项卡按钮 - Angularjs-ui bootstrap.tabs - Adding Next tab button 如何在angularjs bootstrap选项卡上设置活动 - how to set active on angularjs bootstrap tab Angularjs UI引导程序在静态选项卡中动态选择不起作用 - Angularjs UI bootstrap dynamically select among static tabs not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM