当我需要在 Angular 中打开模态窗口时,我创建了一个小演示。使用指令作为模态窗口模板。
我不确定的是我将数据/函数传递给模态的方式。
开启控制器:
$scope.openModal = function($event){
$scope.items = [1,2,3,4,5];
$scope.modalInstance = $modal.open({
template: '<modalwindow></modalwindow>',
scope:$scope,
test:'akex'
});
$scope.modalInstance.result.then(function (selectedItem) {
console.info(selectedItem);
}, function () {
console.info('Modal dismissed at: ' + new Date());
});
和模态指令:
angular.module('angModalApp')
.directive('modalwindow', function () {
return {
templateUrl: 'scripts/directives/modalwindow.tmpl.html',
restrict: 'E',
link: function postLink(scope, element, attrs) {
scope.ok = function () {
scope.modalInstance.close(["a","b","c"]);
};
scope.cancel = function () {
scope.modalInstance.dismiss('cancel');
};
}
};
});
我要问的是你们对这种模态的使用有何看法。有更好的方法吗?
感谢您的时间。
该项目的源代码可以在以下位置找到:https ://github.com/trostik/angular-modal-window-demo