양방향 바인딩 된 개체가 변경 될 때 구성 요소를 다시 초기화하려고합니다.각도 1.5 구성 요소 양방향 바인딩 변경시 초기화
<ul class="nav nav-pills nav-stacked">
<li ng-repeat="tab in tabs"
ng-class="{'active': activeTab.id === tab.id }">
<a href="" ng-click="setActive(tab)"> {{ tab.title }}</a>
</li>
</ul>
<my-component tab="activeTab"></my-component>
app.component('myComponent', {
template: '<div>{{ $ctrl.tab.title }}</div>',
bindings: {
tab: '='
},
controller: function() {
var init = function() {
console.log('hi')
}
init()
}
})
어떻게 init()
이 때마다 변경 사항을 activeTab.id라고 확인 할 수 있습니까?
나는 lifecycle hooks을 들여다 보았지만 그 대답은 아닙니다.
는
$ scope. $ watch()를 사용하십시오. –
@JBNizet은'$ scope. $ watch' 없이는 그것을 할 수있는 방법이 있습니까? 이상적으로 구성 요소에'$ scope '가 없습니다. – user2954587
잘 모르겠지만 구성 요소에서 범위를 사용할 수 있습니다. https://plnkr.co/edit/DpwlIhNLYMypcehpViP1?p=preview –