Reputation: 869
var modalInstance = $modal.open({
templateUrl: 'views/modals/addDevice.html',
controller: ModalCtrl
});
modalInstance.result.then(function (newDevice) {
});
I will implement it in this way:
app.controller("ModalCtrl", function( $scope, $modalInstance ) {
});
But only this way is accepted:
var ModalCtrl = function ($scope, $modalInstance) {
};
Why this happens?
Upvotes: 0
Views: 98
Reputation: 3330
I think you are having issues because the value for your controller name needs to be in quotes -
var modalInstance = $modal.open({
templateUrl: 'views/modals/addDevice.html',
controller: 'ModalCtrl' // <-- this needs to be in quotes
});
Upvotes: 2
Reputation: 3662
This is defining your controller class:
var ModalCtrl = function ($scope, $modalInstance) {
};
you need to create an instance of the class:
var instance = new ModalCtrl(args)
Upvotes: 0
Reputation: 38490
When registering a controller the following way:
app.controller("ModalCtrl", function( $scope, $modalInstance ) {
});
You haven't declared a ModalCtrl
variable so in the following case ModalCtrl
would be undefined:
var modalInstance = $modal.open({
templateUrl: 'views/modals/addDevice.html',
controller: ModalCtrl
});
You can provide the controller name as a string instead:
var modalInstance = $modal.open({
templateUrl: 'views/modals/addDevice.html',
controller: 'ModalCtrl'
});
Upvotes: 3