Angular Inheriting JS 1.X Components

How is inheritance achieved using Angular JS components? My example:

app.component('ResourceForm', controller: [
  function () {
    this.save = () => {
      $http(this.path, this.attributes());
    };
  },
]);

app.component('PersonForm', {
  bindings: {
    person: '<person',
  },
  controller: [
    function () {
      this.path = '/person/' + this.person.id;
      this.attributes = () => { name: this.name };
    },
  ],
});

<!-- templates/person_form.html -->
<form>
  <input type="text" ng-model="$ctrl.name" >
  <submit ng-click="$ctrl.save()"></submit>
</form>
+4
source share
1 answer

As far as I know, there is no real inheritance. You can play with the configurations to get some kind of inheritance:

var cfg = {
  bindings: {
    person: '<person',
    age: '@',
    onNameChange: '@'
  }
}

var component1 = angular.copy(cfg);
component1.controller = ctrl1;
app.component('component1', component1);

var component2 = angular.copy(cfg);
component2.controller = ctrl1;
app.component('component2', component2);
0
source

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


All Articles