Arash Arash - 6 months ago 74
AngularJS Question

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

SSH SSH
Answer

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.