Using the $ injected syntax with additional constructor arguments

advertisements

Looking at the answer here: https://stackoverflow.com/a/19272093/2547709

Using the $inject syntax my controller ends up looking like this:

class MyCtrl {

  public static $inject: string[] = ['$scope'];
  constructor($scope){
    // stuff
  }
}
// register the controller
app.controller("MyCtrl", MyCtrl);

My question is- what happens if I want to pass my own custom arguments to the constructor as well as any injected variables?:

class MyCtrl {

  public static $inject: string[] = ['$scope'];
  constructor($scope, customArg){
    // stuff
  }
}
// Now how do I pass customArg in without it complaining?
app.controller("MyCtrl", MyCtrl(customArg)); // Nope

I feel like I'm missing something fundamental, using this syntax, does everything you pass in to the .controller() function have to be registered with angular and so I shouldn't be trying to pass in custom arguments at all? Or can I pass in an arbitrary value/object? And if so how?


customArg

You cannot pass in custom argument if angular is going to call the constructor. You can however register other things with Angular e.g. Services,Factories,Values(constants) that angular will pass to the controller for you.

More : https://www.youtube.com/watch?v=Yis8m3BdnEM&hd=1