简体   繁体   中英

passing data to angular-ui modal when using controller as vm

i need to pass an object to modal controller , i have tried different approach , here is my final code , the object is passed but i get big error in console

Error: [$injector:unpr] 

here is my code

vm.openAttendeesModal = function (meeting) {

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

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

and here is my modal controller

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;

and here is complete error

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)

the funny part is everything is working , even i have access to passed object , but i just feel something is wrong because of that fat error.

any suggestion ? thanks

try this

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

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

or add controllerAs: "ctrl"

Edit:

if you add "attendeeController as ctrl" in AttendeesModal.cshtml remove it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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