繁体   English   中英

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

[英]How to pass data into an angular.js UI bootstrap modal controller

使用Angular.js UI引导模式,如何将数据传递到模式弹出窗口的控制器中? 我目前正在尝试:

var modalInstance = $modal.open({
    templateUrl: 'partials/confirmation-modal.html',
    controller: 'confirmationModal',
    resolve: {
        foo: function() { return 'bar'; }
    },
    backdrop: 'static',
    keyboard: true
});

控制器confirmationModal为:

    (function(_name) {
        /**
         * @ngInject
         */
        function _controller($scope, foo) {
            console.log(foo);  
        }

        angular
            .module('myApp')
            .controller(_name, _controller);
    })('confirmationModal');

但这与以下错误:

Unknown provider: fooProvider

您可以尝试改为使用angular.module('app').controller(...)定义“ confirmationModal”控制器。

如果要使用字符串来引用控制器,则需要将其注册到角度模块。

因此,您有两种方法可以使其起作用:

1.使用字符串

在模式设置中:

controller: "confirmationModal"

在控制器定义中(假设“ app”是您的模块名称):

angular.module('app').controller("confirmationModal", function($scope, foo) {
    console.log(foo);
});

2.使用功能本身

在模式设置中:

controller: confirmationModal

在控制器定义中:

var confirmationModal = function($scope, foo) {
    console.log(foo);
}

你能说出区别吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM