Hi.
I'm trying pass parameters to a toast controller using locals parameters as indicated in doc.
Here my code:
$materialToast.show({
controller: 'ToastCtrl',
templateUrl: 'toast.tpl.html',
duration: 6000,
position: 'top right',
locals: {p1: 'a', p2: 'b'}
});
I try to use p1 and p2 in toast.tpl.html but there are empty:
{{p1}} - {{p2}}
Close
I try to use p1 and p2 in ToastCtrl but there are undefined.
Locals are injected into the controller, as opposed to being automatically attached to the scope. For example:
app.controller('ToastCtrl', function($scope, p1, p2) {
$scope.p1 = p1;
$scope.p2 = p2;
});
Hope this helps.
@rschmukler I had missed this feature also. I think this _controller injection of locals_ is something we need to clearly document in our API docs.
Thank your @rschmukler !! This works great!
I'm agree with @ThomasBurleson, maybe a little explame could help us.
Thank your!
@ThomasBurleson, @rschmukler - I fell victim to this as well. Kept searching the docs thinking maybe I missed something. After a quick search within the issues and I found this thread and definitely helped. Let me know if and how I can help with improving the docs.
Thanks!
@rschmukler - both $mdToast and $mdDialog need better documentation describing how local arguments are injected as controller constructor arguments. Perhaps a better/more elaborate example? Do you have time to document this soon?
The documentation for $mdDialog has been expanded to cover this.
It will be nice to add example of injection to demos.
Another victim to this here. I still do not find the below pretty clear, though after reading this thread, I clearly understood.
An object containing key/value pairs. The keys will be used as names of values to inject into the controller. For example, locals: {three: 3} would inject three into the controller with the value of 3.
Is there anyway to pass parameters to the controller of a custom preset that was created using the 'addPreset' service function? I'm creating presets in a config provider.
Most helpful comment
Is there anyway to pass parameters to the controller of a custom preset that was created using the 'addPreset' service function? I'm creating presets in a config provider.