我尝试在提交完成后以编程方式关闭基于索引的打开popover。
页面上的HTML:
<a role="button" uib-popover-template="dynamicPopover.templateUrl"
popover-is-open="isPopoverOpen[$index]" ng-click="openPopover($index)>
open popover
</a>
popover模板:
<input ng-model="input.value">
<button class="btn" ng-click="saveValue()">submit</button>
控制器:
$scope.openPopover = openPopover;
$scope.saveValue = saveValue;
$scope.dynamicPopover = {
templateUrl: 'templates/test_popup.html'
};
function openPopover(index){
$scope.isPopoverOpen[index] = true;
$scope.popIndex = index;
}
function saveValue(index){
var data = {
value: $scope.input.value
}
$http.post('url', data)
.then(function (res) {
$scope.isPopoverOpen[$scope.popIndex] = false;
}, function (err) {
});
}
}
所有这些都有效,除非在ajax完成时关闭popover,所以这甚至可能吗?
答案 0 :(得分:1)
您可以保存索引并在saveValue函数中使用它
<强> JS 强>:
$scope.openPopover(index){
$scope.isPopoverOpen[index] = true;
$scope.selectedIndex = index;
}
$scope.saveValue=function(){
var data = {
value: $scope.input.value
}
$http.post('url', data)
.then(function (res) {
$scope.isPopoverOpen[$scope.selectedIndex ] = false;
}, function (err) {
});
}
}