A
A
Andrew2017-11-07 15:11:02
Angular
Andrew, 2017-11-07 15:11:02

Is it possible to change the constructor of a controller depending on different conditions?

Let's say there is a record editing form. This form is called from different places by users with different roles. Depending on the role, after closing the form, some data should change, which for each role is slightly different. I think that it is best to define in the constructor which functions to load, save, change data, and to which place to return after closing.
Now the transition to the post editing form looks something like this:

export class Controller {
    constructor($scope: IScope, public $location: ng.ILocationService) {
        $scope.edit = this.edit;
    }
  edit = (id) => {
    this.$location.path("/edit/" + id);
  }
}

The edit function is hung on ng-click.
Question: is it possible to define a constructor that will create a controller that will be called when going to /edit?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question