【发布时间】:2017-03-15 10:12:11
【问题描述】:
考虑一下这个简化的 Angular 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}}
点击组件按钮时,count变量正在更新('&' onUpdate绑定好)。
现在我想要一个从 ui.router 到组件的路由:
$stateProvider.state({
name: 'state1',
component: 'mainComponent',
url: "#"
});
导航到状态,导致Cannot read property '2' of null,删除 onUpdate 成员修复错误但破坏绑定。
我做错了什么?使用ui.router路由到组件时如何绑定组件的回调方法。
【问题讨论】:
标签: javascript angularjs angular-ui-router angular-components