How to achieve base class and derived class concept in angularjs?

In angular js, how to get the base class and the concept of the derived class ?. My requirement In the base controller, I need to create some method and derived controller, I have to override this method. Can anyone help me on this. Thanks..

+4
source share
1 answer

1 Non-following method:

I think you can achieve this somehow like this:

function ChildController($injector, $scope) {
  $injector.invoke(ParentController, this, {
      $scope: $scope
  });
}

2 Prototypic inheritance

(ES5 browser support required)

angular.inherits = function (ctor, superCtor) {
    ctor.super_ = superCtor;
    ctor.prototype = Object.create(superCtor.prototype, {
        constructor: {
            value: ctor,
            enumerable: false
        }
    });
};

Using:

function ChildController($scope) {
    // Invoke the parent constructor.
   ChildController.super_.apply(this, arguments);
}

angular.inherits(ChildController, ParentController);

Code samples from here: https://github.com/exratione/angularjs-controller-inheritance

3 Get Typescript

, , $scope. , , .

typescript, .

-1

Source: https://habr.com/ru/post/1623714/


All Articles