将控制器用作vm时,将数据传递给angular-ui模态

时间:2016-05-29 10:20:46

标签: angularjs angular-ui-bootstrap angular-ui

我需要将一个对象传递给模态控制器,我尝试了不同的方法,这是我的最终代码,对象被传递但是我在控制台中出现了大错误

Error: [$injector:unpr] 

这是我的代码

vm.openAttendeesModal = function (meeting) {

                var modalInstance = $modal.open({
                    templateUrl: '/App/Main/views/meetings/AttendeesModal.cshtml',
                    controller: 'attendeeController',

                    resolve: {
                        meetingSelected: function () { return meeting }
                    }
                });
            }

这是我的模态控制器

angular
      .module('App')
      .controller('attendeeController', attendeeController);

    attendeeController.$inject = ['meetingSelected', '$scope', '$modal', 'meetingService'];

    function attendeeController(meetingSelected,$scope, $modalInstance, meetingService) {
        /* jshint validthis:true */
        var vm = this;
        vm.meetingSelected = meetingSelected;

这是完整的错误

angular.js:12520 Error: [$injector:unpr] http://errors.angularjs.org/1.4.8/$injector/unpr?p0=meetingSelectedProvider%20%3C-%20meetingSelected%20%3C-%20attendeeController
    at Error (native)

有趣的部分是一切正常,即使我可以访问传递的对象,但我只是觉得因为那个胖的错误而出错了。

有什么建议吗? 感谢

1 个答案:

答案 0 :(得分:1)

试试这个

 var modalInstance = $modal.open({
                templateUrl: '/App/Main/views/meetings/AttendeesModal.cshtml',
                controller: 'attendeeController as ctrl',

                resolve: {
                    meetingSelected: function () { return meeting }
                }
            });

或添加controllerAs: "ctrl"

修改

如果您在"attendeeController as ctrl"中添加AttendeesModal.cshtml,请将其删除。