我对AngularJs还是比较新的,我创建了一个非常通用的模态视图,我想要做的是能够全局使用它来代替其他当前alert()的,但是一些他们将有不同的文本和按钮等等...什么是实例化全局控制器的最佳方法,但为每个控制器设置不同的首选项?使用角模态作为警报
这是我的例子:
controller.js
(function() {
var test= angular.module('test');
test.controller('modal', function ($scope, $uibModal) {
$scope.modal= function() {
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'template.html',
controller: 'test',
scope: $scope,
size: 'medium',
backdrop: 'static'
});
modalInstance.result.then(function() {
}, function() {
console.log("dismissed")
});
}
});
test.controller('modalInstance', function ($scope, $uibModalInstance) {
$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
};
});
})
();
模板,其中警报()将
<div class="modal-header">
</div>
<div class="modal-body" style="margin: 0 auto;" ng-controller="exportController">
<p>Are you sure you want to continue?</p>
</div>
<div class="modal-footer btn-group-xs">
<button class="btn btn-primary" type="button" ng-click="open()">Ok</button>
<button class="btn btn-primary" type="button" ng-click="cancel()">Cancel</button>
</div>
例
$scope.launchTerms = function($event) {
$event.preventBasick();
alert("Launch Terms");
};
任何人都可以举个例子吗?
你有没有一个例子 – user2402107
没有打算花时间创建一个,但添加了一个演示链接来回答。非常基本的...只是打开一个模式,并添加了一些文本从'alert()' – charlietfl
谢谢我仍然有点困惑在使用他们在一个单独的控制器 – user2402107