I want to open a modal declaring the modal file name, and an image url I want to use in the scope of the modal. e.g.:
ng-click="showModal('screenshot','http://placehold.it/800x550')"
When I try the above I'm getiing the following error:
Error: [$injector:unpr] Unknown provider: imageUrlProvider <- imageUrl <- ModalController
Here's the code I'm trying - Modal Controller:
hmwsApp.controller('ModalController', function($scope, close, imageUrl) {
$scope.imageUrl = imageUrl;
$scope.close = function(result) {
close(result, 500); // close after 500ms to allow for bootstrap to animate
};
});
Main Controller:
hmwsApp.controller('mainController', ['$scope', '$http', '$rootScope', 'ModalService', function($scope, $http, $rootScope, ModalService) {
$scope.showModal = function(modalUrl, imageUrl) {
ModalService.showModal({
templateUrl: '/views/modals/' + modalUrl + '.html',
controller: "ModalController",
resolve: {
imageUrl: function () {
return imageUrl;
}
}
})
.then(function(modal) {
modal.element.modal();
modal.close.then(function(result) {
$scope.message = "Image shown " + result;
});
});
};
}]);
Is there anything obviously wrong?
asked Apr 16, 2015 at 8:02
StudioTime
24.4k40 gold badges129 silver badges219 bronze badges
1 Answer 1
What you did here:
hmwsApp.controller('ModalController', function($scope, close, imageUrl)
is injected imageUrl into your controller.
What you wanted to do is create an input param named imageUrl inside a controller method:
hmwsApp.controller('ModalController', function($scope) {
$scope.showModal = function(screenshot,imageUrl){
// do something
}
......
});
answered Apr 16, 2015 at 8:05
Amir Popovich
30.1k9 gold badges58 silver badges102 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
StudioTime
But I already have that function in the
mainController - are you saying to replicate it in the ModalController? How would my code block look fully? Apologies if I'm missing something, new to Angularlang-js
imageUrlas object and not primitive? for example:resolve: { imageUrl: function () { return {data: imageUrl}; } }