Return 从 Angular Bootstrap 模态工厂中选择使用控制器作为
Return selection from Angular Bootstrap modal factory using controller as
我正在尝试使用模态对话框作为选择列表。我已将模态对话框配置为工厂。
如何从 http://plnkr.co/edit/fVpNtrr4Ez68yWYUlgnO?p=preview 处获取代码 return 从模态 window 中选择的人?
var selectModal = function ($modal) {
function show(personList) {
var modalOptions = {
templateUrl: "select-modal.html",
controller: selectModalInstanceCtrl,
controllerAs: "modal",
windowClass: "ab-modal-window",
resolve: {
personList: function () { return personList; }
}
};
var modalInstance = $modal.open(modalOptions);
modalInstance.result.then(function (person) {
return person;
});
}
return {
show: show
};
};
var selectModalInstanceCtrl = function ($modalInstance, personList) {
var modalVm = this;
modalVm.personList = personList;
modalVm.selectPerson = function (person) {
$modalInstance.close(person);
};
modalVm.ok = function () {
$modalInstance.dismiss("ok");
};
};
var mainCtrl = function (selectModal)
{
var vm = this;
vm.personList = ['Tom','Dick','Harry','Jane'];
vm.selectedPerson = null;
vm.showSelectModal = function () {
vm.selectedPerson = selectModal.show(vm.personList, vm.selectedPerson);
};
};
selectModalInstanceCtrl.$inject = ["$modalInstance", "personList"];
selectModal.$inject = ['$modal'];
mainCtrl.$inject = ['selectModal'];
angular.module('app', ['ui.bootstrap']);
angular.module('app').factory('selectModal', selectModal);
angular.module('app').controller('mainCtrl', mainCtrl);
在script.js的第18行,选择的人在那里,但我无法将其传回主控制器。
// 代码在此处
var selectModal = function ($modal) {
function show(personList) {
var modalOptions = {
templateUrl: "select-modal.html",
controller: selectModalInstanceCtrl,
controllerAs: "modal",
windowClass: "ab-modal-window",
resolve: {
personList: function () { return personList; }
}
};
var modalInstance = $modal.open(modalOptions);
return modalInstance;
}
return {
show: show
};
};
var selectModalInstanceCtrl = function ($modalInstance, personList) {
var modalVm = this;
modalVm.personList = personList;
modalVm.selectPerson = function (person) {
$modalInstance.close(person);
};
modalVm.ok = function () {
$modalInstance.dismiss("ok");
};
};
var mainCtrl = function (selectModal)
{
var vm = this;
vm.personList = ['Tom','Dick','Harry','Jane'];
vm.selectedPerson = null;
vm.showSelectModal = function () {
var modalInstance = selectModal.show(vm.personList);
modalInstance.result.then(function (person) {
vm.selectedPerson = person;
});
};
};
selectModalInstanceCtrl.$inject = ["$modalInstance", "personList"];
selectModal.$inject = ['$modal'];
mainCtrl.$inject = ['selectModal'];
angular.module('app', ['ui.bootstrap']);
angular.module('app').factory('selectModal', selectModal);
angular.module('app').controller('mainCtrl', mainCtrl);
我正在尝试使用模态对话框作为选择列表。我已将模态对话框配置为工厂。
如何从 http://plnkr.co/edit/fVpNtrr4Ez68yWYUlgnO?p=preview 处获取代码 return 从模态 window 中选择的人?
var selectModal = function ($modal) {
function show(personList) {
var modalOptions = {
templateUrl: "select-modal.html",
controller: selectModalInstanceCtrl,
controllerAs: "modal",
windowClass: "ab-modal-window",
resolve: {
personList: function () { return personList; }
}
};
var modalInstance = $modal.open(modalOptions);
modalInstance.result.then(function (person) {
return person;
});
}
return {
show: show
};
};
var selectModalInstanceCtrl = function ($modalInstance, personList) {
var modalVm = this;
modalVm.personList = personList;
modalVm.selectPerson = function (person) {
$modalInstance.close(person);
};
modalVm.ok = function () {
$modalInstance.dismiss("ok");
};
};
var mainCtrl = function (selectModal)
{
var vm = this;
vm.personList = ['Tom','Dick','Harry','Jane'];
vm.selectedPerson = null;
vm.showSelectModal = function () {
vm.selectedPerson = selectModal.show(vm.personList, vm.selectedPerson);
};
};
selectModalInstanceCtrl.$inject = ["$modalInstance", "personList"];
selectModal.$inject = ['$modal'];
mainCtrl.$inject = ['selectModal'];
angular.module('app', ['ui.bootstrap']);
angular.module('app').factory('selectModal', selectModal);
angular.module('app').controller('mainCtrl', mainCtrl);
在script.js的第18行,选择的人在那里,但我无法将其传回主控制器。
// 代码在此处
var selectModal = function ($modal) {
function show(personList) {
var modalOptions = {
templateUrl: "select-modal.html",
controller: selectModalInstanceCtrl,
controllerAs: "modal",
windowClass: "ab-modal-window",
resolve: {
personList: function () { return personList; }
}
};
var modalInstance = $modal.open(modalOptions);
return modalInstance;
}
return {
show: show
};
};
var selectModalInstanceCtrl = function ($modalInstance, personList) {
var modalVm = this;
modalVm.personList = personList;
modalVm.selectPerson = function (person) {
$modalInstance.close(person);
};
modalVm.ok = function () {
$modalInstance.dismiss("ok");
};
};
var mainCtrl = function (selectModal)
{
var vm = this;
vm.personList = ['Tom','Dick','Harry','Jane'];
vm.selectedPerson = null;
vm.showSelectModal = function () {
var modalInstance = selectModal.show(vm.personList);
modalInstance.result.then(function (person) {
vm.selectedPerson = person;
});
};
};
selectModalInstanceCtrl.$inject = ["$modalInstance", "personList"];
selectModal.$inject = ['$modal'];
mainCtrl.$inject = ['selectModal'];
angular.module('app', ['ui.bootstrap']);
angular.module('app').factory('selectModal', selectModal);
angular.module('app').controller('mainCtrl', mainCtrl);