我将创建一个指令,打开一个Angular Bootstrap UI模态窗口。当关闭模态窗口时,我希望执行从指令属性传递的函数。这是我目前的代码:
在弹出窗口的模板中,我有一个绑定到关闭按钮的函数,它调用了“PopupController”中的一个函数,该函数再调用指令链接函数中的closeFn。
据我所知,scope.onClose()应该执行由on-close属性指定的函数?我没有提供很多代码,因为原始代码很多,但如果有帮助的话,我可以添加更多。
这是在index.tpl.html中的代码:
<popup class="something" .. on-close="update()"></popup>
指令代码,仅限于作用域定义,因为此前有很多代码:
scope: {
onClose: "&"
},
link: function(scope, element, attr){
//some code
......
scope.closeFn = function(){
scope.onClose();
}
//opening of the modal:
var modalInstance = $modal.open({
....
templateUrl: 'path/to/template.tpl.html,
controller: 'PopupController',
scope: scope,
....
});
在弹出窗口的模板中,我有一个绑定到关闭按钮的函数,它调用了“PopupController”中的一个函数,该函数再调用指令链接函数中的closeFn。
<button type="button" class="btn-close btn btn-large" ng-click="closePopup()">Close
</button>
并且在'PopupController'中:
$scope.closeUploadPopup = function () {
$scope.$parent.closeFn();
$modalInstance.close();
};
据我所知,scope.onClose()应该执行由on-close属性指定的函数?我没有提供很多代码,因为原始代码很多,但如果有帮助的话,我可以添加更多。
destination[scopeName] = function(locals) { return parentGet(scope, locals); };
来自Angular源代码其中locals是未定义的。可能是我绑定函数调用的方式不正确吗? - Loshmeey