简体   繁体   English

如何将数据传递到angular.js UI引导模式控制器

[英]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.

相关问题 将信息从Angular.js控制器传递到引导模式 - Pass information to bootstrap modal from Angular.js controller AngularJS:Angular UI Bootstrap,将数据从模态传递到控制器 - AngularJS: Angular UI Bootstrap, pass data from modal to controller Angular.js-如何将数据从控制器传递到视图 - Angular.js - How to pass data from controller to view 如何将表单数据从角度ui bootstrap模式传递到视图 - How to pass form data from angular ui bootstrap modal to view 如何使用角度ui模态将数据传递到控制器? - How to pass data to the controller using angular ui modal? 如何将函数传递给角度ui bootstrap模态 - How to pass a function to angular ui bootstrap modal angular.js ui-router 不传递数据 - angular.js ui-router pass no data 如何使用Angular.js和UI Bootstrap创建分页 - How Create Pagination with Angular.js and UI Bootstrap Angular UI Bootstrap Modal在后台单击时将数据传递回父控制器/ ESC键盘关闭 - Angular UI Bootstrap Modal pass data back to parent controller on background click / ESC keyboard close 如何在我的指令中连接控制器以在angular.js中插入数据和添加引导选择? - How to connect my controller in my directive for inserting data and adding bootstrap select in angular.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM