【发布时间】:2016-06-16 00:25:38
【问题描述】:
当前子组件尝试删除父组件的数组时遇到问题。
父组件:
@Component({
selector: 'parent',
templateUrl: 'app/templates/parent.html'
})
export class ParentComponent {
public items = [];
}
父 HTML
<child [items]="items"></child>
<product *ngFor="let item of items><product>
子组件
@Component({
selector: 'child',
templateUrl: 'app/templates/child.html'
})
export class ChildComponent{
@Input() items;
emptyItems() {
this.items = [];
}
addItem() {
this.items.push({'title': 'foo'});
}
}
但是,当我调用 emptyItems/addItem 函数时,子视图中的 items 数组将反映更改,但在父组件上它不会更改。
我需要使用输出吗?
【问题讨论】:
标签: javascript angular