Reputation: 2124
I am trying to pass a variable with the md dialog service but it is giving me unknown provider error for the md dialog service
What I have tried so far is as follows -
$mdDialog.show({
controller: 'SignInModalController',
templateUrl: 'views/partials/signin_modal.html',
targetEvent: ev,
size: 'sm',
parent: angular.element(document.body),
locals: {
"login_cookies": cookies
}
})
I am trying to pass this locals object to the sign in modal controller which has the following code - >
app.controller('SignInModalController', ['$scope', '$stateParams', '$location', '$mdDialog', 'Auth', '$mdToast', 'login_cookies',
function($scope, $stateParams, $location, $mdDialog, Auth, $mdToast, login_cookies) {
and I am getting the following error message in console after this - >
Error: [$injector:unpr] Unknown provider: login_cookiesProvider <- login_cookies <- SignInModalController
http://errors.angularjs.org/1.4.3/$injector/unpr?p0=login_cookiesProvider%20%3C-%20login_cookies%20%3C-%20SignInModalController
Also the sign in modal controller file is lazily loaded during the initial bootstrapping of angular app like this - >
.state('app', {
abstract: true,
url: '/app?feedback',
views: {
'': {
templateUrl: 'views/layout.html'
},
'aside': {
templateUrl: 'views/aside.html'
},
'content': {
templateUrl: 'views/content.html'
}
},
resolve: load([
'scripts/google_analytics.js',
'scripts/controllers/app/aside.js',
'scripts/controllers/app/navbar.js',
'scripts/controllers/app/reach_us.js',
'scripts/controllers/app/labs/filter.ctrl.js',
'scripts/controllers/app/signin_modal.js',
'scripts/controllers/app/feedback.js'])
})
What other things should I check in order to resolve this error ?
On setting a breakpoint in the dialog controller as soon as I open the dialog I get the following result -
As you can see the passed array (list_cookies
) does have a value and yet in the console I am getting this error -
Any suggestions ?
Upvotes: 3
Views: 1709
Reputation: 1
Since I can't comment on deadman's latest comment, this is more of follow up on how the issue was identified/solved by him.
Try remove ng-controller in the md-dialog tag. I think that is because when you call $mdDialog.show, you passed in the providers, in this case, the locals. However, if you have ng-controller in the md-dialog tag, it is declared without the context of the the locals.
Upvotes: 0
Reputation: 193
I think the problem is you want to inject dialogLocals
into your SignInModalController
and then access the login_cookies
as dialogLocals.login_cookies
.
So change:
app.controller('SignInModalController', ['$scope', '$stateParams', '$location', '$mdDialog', 'Auth', '$mdToast', 'login_cookies', function($scope, $stateParams, $location, $mdDialog, Auth, $mdToast, login_cookies) {
To:
app.controller('SignInModalController', ['$scope', '$stateParams', '$location', '$mdDialog', 'Auth', '$mdToast', 'dialogLocals', function($scope, $stateParams, $location, $mdDialog, Auth, $mdToast, dialogLocals) {
Then access from your SignInModalController
as:
dialogLocals.login_cookies
Upvotes: -1