Simple way of opening modal with ngDialog is this:
ngDialog.open({
template: 'template.html',
controller: 'someCtrl'
})
How can I send variables to that 'someCtrl'?
Is there such thing as 'resolve' in ngDialog?
Example from angular-bootstrap modal:
$modal.open({
template: "<p>This is template</p>",
controller: "someCtrl",
resolve: {
someVar: function(){
return "Value of someVar"
}
}
})
this would open the modal send the 'someVar' to the responsible Controller.
UPDATE:
It seems like new version of ngDialog added this feature:
ngDialog.open({
controller: function Ctrl(dep) {/*...*/},
resolve: {
dep: function depFactory() {
return 'dep value';
}
}
});
Well looks like ngDialog doesn't support resolve and custom injection in controller. However you can alway do it manually by creating controller
instance yourself:
ngDialog.open({
scope: $scope,
template: 'template.html',
controller: $controller('someCtrl', {
$scope: $scope,
name: 'Thomas'
})
});
then in controller you will be able to access injected service/variable:
app.controller('someCtrl', function($scope, name) {
console.log(name); // Thomas
});
However there is a caveat with this approach, because when controller in instantiated by ngDialog
itself it also injects $element
service in it, which is an angular.element
instance of the opened dialog HTML (however I doubt it's even necessary in controller). But you should know it anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With