Angular JS 1.X组件继承

时间:2017-10-31 04:30:20

标签: angularjs

如何使用Angular JS组件实现继承?我的样本是:

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>

1 个答案:

答案 0 :(得分:0)

据我所知,没有真正的遗产。你可以玩配置来获得某种继承:

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);