Javascript 从工厂调用时如何从控制器关闭角带模式
我看到很多人都在努力从控制器上关闭角带模型。我得到了一些答案,但实际上它们的做法不同(我不想更改代码样式)。我使用modalFactory打开modal,因此我没有modalInstance。所以我完全不确定,我如何才能结束这一切 使用angular bootstrap,我知道我可以注入uibModalInstance并调用uibModalInstance.disclose()关闭函数。但我如何能做类似的角带模式 这是我的工厂:Javascript 从工厂调用时如何从控制器关闭角带模式,javascript,angularjs,angular-strap,Javascript,Angularjs,Angular Strap,我看到很多人都在努力从控制器上关闭角带模型。我得到了一些答案,但实际上它们的做法不同(我不想更改代码样式)。我使用modalFactory打开modal,因此我没有modalInstance。所以我完全不确定,我如何才能结束这一切 使用angular bootstrap,我知道我可以注入uibModalInstance并调用uibModalInstance.disclose()关闭函数。但我如何能做类似的角带模式 这是我的工厂: (function (app) { 'use strict' a
(function (app) {
'use strict'
app.factory('modalFactory', ['$modal', function ($modal) {
var local = this;
local.modalInstance = ['$scope',
function ($scope) {
$scope.myVar = "Some variable input ";
$scope.closeModal = function(){
console.log("CLose function has been called..")
// How I can close this.
}
}];
return {
openMyModal: function (ip) {
$modal({
templateUrl: 'myModal.html',
controller: local.modalInstance,
size: 'lg',
resolve: {
ip: function () {
return ip;
}
}
})
}
}
}])
})(app)
完整的plunkr可用。调用$scope.$hide()
在您的内部克隆解调方法
(function (app) {
'use strict'
app.factory('modalFactory', ['$modal', function ($modal) {
var local = this;
local.modalInstance = ['$scope',
function ($scope) {
$scope.myVar = "Some variable input ";
$scope.closeModal = function(){
console.log("CLose function has been called..")
$scope.$hide();
}
}];
return {
openMyModal: function (ip) {
$modal({
templateUrl: 'myModal.html',
controller: local.modalInstance,
size: 'lg',
resolve: {
ip: function () {
return ip;
}
}
})
}
}
}])
})(app);
更新plunker:您可以在
$scope
上调用$hide
方法,检查OMG,这太简单了。我曾使用$hide()关闭模板中的modal,但从未想过这必须在$scope中可用。非常感谢你帮了我的忙。当然。。所以不允许我在接下来的2分钟内接受这个。。我很快就会接受的