Arash Arash - 4 months ago 61x
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 = ${
templateUrl: '/App/Main/views/meetings/AttendeesModal.cshtml',
controller: 'attendeeController',

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

and here is my modal controller

.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]$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 ?


try this

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

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

or add controllerAs: "ctrl"


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