0
考慮這個簡化的角1.5.x的成分(所有在jsfiddle):綁定 '&' 在路由組件方法
appModule.component('mainComponent', {
controller: function() {
var x = 0;
this.broadcast = function() {
this.onUpdate({
count: x++
});
};
this.broadcast();
},
bindings: {
onUpdate: '&'
},
template: '<input type="button" ng-click="$ctrl.broadcast()" value="add"/>'
});
HTML(在體內)
<main-component on-update="this.count = count"></main-component>
Value in parent: {{count}}
當單擊組件按鈕,計數變量正在更新('&'onUpdate綁定得很好)。現在
我想有從ui.router到部件的路由:
$stateProvider.state({
name: 'state1',
component: 'mainComponent',
url: "#"
});
導航到狀態,導致Cannot read property '2' of null
,去除的onUpdate構件固定的錯誤,但打破約束力。
我在做什麼錯?將ui.router路由用於組件時,綁定組件的回調方法的方法是什麼?