0
我有哪里我使用ui.bootstrap
项目,并根据教程我跟着我必须将它设置与此类似:呼叫模态功能 - AngularJS
'use strict';
angular.module('academiaUnitateApp')
.controller('EntryCtrl', function ($scope, $modal) {
$scope.open = function() {
var modalInstance = $modal.open({
templateUrl: 'modal.html',
controller: 'ModalCtrl'
})
};
});
'use strict';
angular.module('academiaUnitateApp')
.controller('ModalCtrl', function ($scope, $modalInstance) {
$scope.ok = function() {
$modalInstance.close();
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
$scope.delete = function() {
$modalInstance.dismiss('cancel');
};
});
<script type="text/ng-template" id="modal.html">
<div class="modal-header">
<h3 class="modal-title">I'm a modal!</h3>
</div>
<div class="modal-body">
<p class="alert alert-danger">
WARNING: By deleting the article all it's nested articles will be moved to the article holding this one.
<br/>
Do you still want to delete this article?
</p>
<button class="btn btn-primary" ng-click="delete()">Yes</button>
<button class="btn btn-primary" ng-click="cancel()">No</button>
<span ng-show="error.state" class="alert alert-danger">{{ error.message }}</span>
<span ng-show="done.state" class="alert alert-success">{{done.message}}</span>
</div>
<div class="modal-footer">
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
</script>
这项工作发现和所有,但是如果我想要将$scope.delete
功能移到EntryCtrl
控制器中而不是将它放在单独的控制器中,该怎么办?
快速另一个问题:它会如何看,如果我想使用一些来自新的无名控制器中'EntryCtrl'的变量? –
我编辑了我的答案以添加该部分。你能否验证它是否按预期工作? –
工作。但是你需要在函数前写上''outerscope''。你错过了''' –