0

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?

1

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.