我有一个如下指令
<modal title="Error" id='successmessage' visible="successmessage">
<form role="form">
Action was uccesful
<span class="clearfix"></span>
<button type="submit" class="btn btn-primary" ng-click="closemodal('successmessage');>Ok</button>
</form>
</modal>
<modal title="Error" id='errormessage' visible="errormessage">
<form role="form">
Action was not Succesful
<span class="clearfix"></span>
<button type="submit" class="btn btn-primary" ng-click="closemodal('errormessage');>Ok</button>
</form>
我有一个像
这样的表格$scope.closemodal = function(scopename)
{
$scope[scopename] = false;
}
当我点击像
这样的closemodal时,我正试图关闭模态public static List<Type> getProtocolls(Class clazz, Transaction trx) {
Iterator<Type> iterator = trx.getContext().getProtocolls()
List<Type> list = null;
while (iterator.hasNext()) {
if (iterator.next() instanceof clazz) {
list.add(iterator.next())
}
}
return list;
}
我试图通过将属性设置为false来关闭模型。但它不起作用。我该如何解决?
答案 0 :(得分:1)
这就是你要找的东西:
angular.module('my-app', [])
.directive('modal', function () {
return {
template: '<div class="modal fade">' +
'<div class="modal-dialog">' +
'<div class="modal-content">' +
'<div class="modal-header">' +
'<button type="button" class="close" ng-click="closemodal()">×</button>' +
'<h4 class="modal-title">{{ modalTitle }}</h4>' +
'</div>' +
'<div class="modal-body" ng-transclude></div>' +
'</div>' +
'</div>' +
'</div>',
restrict: 'E',
transclude: true,
replace:true,
link: function postLink(scope, element, attrs) {
scope.modalTitle = attrs.title;
scope.showModal = true;
scope.closemodal = function () {
scope.showModal = false;
};
}
};
});
答案 1 :(得分:0)
使用ng-show
这样的代替visible
:
<modal title="Error" id='errormessage' ng-show="errormessage">
<form role="form">
Action was not Succesful
<span class="clearfix"></span>
<button type="submit" class="btn btn-primary"
ng-click="closemodal(errormessage);>Ok</button>
</form>
</modal>
现在检查上面的代码并传递变量而不是值:
ng-click="closemodal('errormessage')
答案 2 :(得分:0)
当一个作用域继承一个原语时,在父作用域中更改它将不会对继承的作用域进行更改,在您的情况下是指令作用域。
你应该将指令传递给一个对象,而不是一个原语。
这里的芦苇更多: Angular js scope on nested template