[英]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.