[英]How to pass data into an angular.js UI bootstrap modal controller
Using Angular.js UI bootstrap modal, how can I pass data into a modal popup's controller? 使用Angular.js UI引导模式,如何将数据传递到模式弹出窗口的控制器中? I am currently trying:
我目前正在尝试:
var modalInstance = $modal.open({
templateUrl: 'partials/confirmation-modal.html',
controller: 'confirmationModal',
resolve: {
foo: function() { return 'bar'; }
},
backdrop: 'static',
keyboard: true
});
The controller confirmationModal
is: 控制器
confirmationModal
为:
(function(_name) {
/**
* @ngInject
*/
function _controller($scope, foo) {
console.log(foo);
}
angular
.module('myApp')
.controller(_name, _controller);
})('confirmationModal');
But this errors with: 但这与以下错误:
Unknown provider: fooProvider
You can try to define the "confirmationModal" controller with angular.module('app').controller(...)
instead. 您可以尝试改为使用
angular.module('app').controller(...)
定义“ confirmationModal”控制器。
If you want to use a string to refer to a controller, you need to register it to an angular module. 如果要使用字符串来引用控制器,则需要将其注册到角度模块。
So, you have two ways to make it work: 因此,您有两种方法可以使其起作用:
1.Use string 1.使用字符串
In modal settings: 在模式设置中:
controller: "confirmationModal"
In controller definition (assume "app" is your module name): 在控制器定义中(假设“ app”是您的模块名称):
angular.module('app').controller("confirmationModal", function($scope, foo) {
console.log(foo);
});
2.Use function itself 2.使用功能本身
In modal settings: 在模式设置中:
controller: confirmationModal
In controller definition: 在控制器定义中:
var confirmationModal = function($scope, foo) {
console.log(foo);
}
Can you tell the difference? 你能说出区别吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.