Reputation: 2725
Is there a way to use injected into controller modules in the view directly without binding it to controller explicitly? In other words, is there something along the lines of
<p>{{$ctrl.$injectedIntoThisController.$stateParams.name}}<p>
for when $stateParams is injected into controller?
Upvotes: 0
Views: 39
Reputation: 8652
You cannot use a service without injecting it, you can use the $injector
service to inject services dinamically based on a condition and then bind what you need to the view.
angular.controller('MyCtrl', ['$injector', function($injector){
if(something){
var service = $injector.get('MyService');
this.prop = service.prop;
}
}])
and in your view bind the property.
<div ng-controller="MyCtrl as $ctrl">
<p>{{$ctrl.prop}}<p>
</div>
https://docs.angularjs.org/api/auto/service/$injector
Upvotes: 1