2017-10-31 2 views
4

Angular JS 구성 요소를 사용하여 상속을 얻으려면 어떻게해야합니까? 내 샘플 :각도 JS 1.X 구성 요소 상속

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> 

답변

0

내가 아는 한 실제적인 상속은 없습니다. configs를 사용하여 상속받을 수 있습니다.

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); 
관련 문제