AngularJS 并使用一种模式实现多种功能
AngularJS and using one modal for multiple functions
我正在开发一个使用 WEB API(来自 C# 后端)并在前端使用 AngularJS 的网站。有一次,我有一个 ng-click 打开模式并警告用户继续将 删除所有测试记录 (不要太担心这个)。
单击继续后,将调用 sproc(来自 web-api controller->service->EDMX sproc)等等。无论如何,我还有另外两个按钮做同样的事情(显示模态,但 略有不同的措辞 )并调用相同的存储过程,但在存储过程触发后它重定向到不同的页面。
是否可以使用 一个模态 ,使用不同的 模板网址 并重定向到 不同的页面当用户单击 proceed/the 模式关闭取决于按下的按钮?
P.S。注意模态不是模型
我针对这种情况写了一个可重复使用的指令。
它允许您传入各种模板 url
<a template-link="/html/delete.html" confirm-dialog="deleteElement()">Delete</a>
'use strict';
/*global angular,console,$:false*/
angular.module('testmodule').
directive(confirmDialog', ['$modal', function($modal) {
var modalInstance = null;
var ModalCtrl = function($scope, $modalInstance) {
$scope.ok = function() {
$modalInstance.close();
};
$scope.cancel = function() {
if (angular.isDefined(modalInstance) && modalInstance !== null) {
$modalInstance.dismiss('cancel');
}
};
};
return {
restrict: 'A',
scope: {
confirmDialog:"&",
tLink: '@templateLink'
},
link: function(scope, element, attrs) {
element.bind('click', function() {
modalInstance = $modal.open({
scope: scope,
templateUrl: tLink,
controller: ['$scope', '$modalInstance', ModalCtrl],
backdrop: 'static',
keyboard: false,
});
modalInstance.result.then(function() {
scope.confirmDialog();
}, function() {
//Modal dismissed
});
});
}
};
}]);
我正在开发一个使用 WEB API(来自 C# 后端)并在前端使用 AngularJS 的网站。有一次,我有一个 ng-click 打开模式并警告用户继续将 删除所有测试记录 (不要太担心这个)。
单击继续后,将调用 sproc(来自 web-api controller->service->EDMX sproc)等等。无论如何,我还有另外两个按钮做同样的事情(显示模态,但 略有不同的措辞 )并调用相同的存储过程,但在存储过程触发后它重定向到不同的页面。
是否可以使用 一个模态 ,使用不同的 模板网址 并重定向到 不同的页面当用户单击 proceed/the 模式关闭取决于按下的按钮?
P.S。注意模态不是模型
我针对这种情况写了一个可重复使用的指令。
它允许您传入各种模板 url
<a template-link="/html/delete.html" confirm-dialog="deleteElement()">Delete</a>
'use strict';
/*global angular,console,$:false*/
angular.module('testmodule').
directive(confirmDialog', ['$modal', function($modal) {
var modalInstance = null;
var ModalCtrl = function($scope, $modalInstance) {
$scope.ok = function() {
$modalInstance.close();
};
$scope.cancel = function() {
if (angular.isDefined(modalInstance) && modalInstance !== null) {
$modalInstance.dismiss('cancel');
}
};
};
return {
restrict: 'A',
scope: {
confirmDialog:"&",
tLink: '@templateLink'
},
link: function(scope, element, attrs) {
element.bind('click', function() {
modalInstance = $modal.open({
scope: scope,
templateUrl: tLink,
controller: ['$scope', '$modalInstance', ModalCtrl],
backdrop: 'static',
keyboard: false,
});
modalInstance.result.then(function() {
scope.confirmDialog();
}, function() {
//Modal dismissed
});
});
}
};
}]);