【发布时间】:2016-03-16 00:53:09
【问题描述】:
我在父组件中有一个变量可能会被子组件更改,父组件将在视图中使用此变量,因此必须传播更改。
import {Component, View} from 'angular2/core';
@Component({selector: 'parent'})
@View({
directives: [Child],
template: `<childcomp></childcomp>`
})
class Parent {
public sharedList = new Array();
constructor() {
}
}
@Component({selector: 'child'})
@View({template: `...`})
class Child {
constructor() {
//access 'sharedList' from parent and set values
sharedList.push("1");
sharedList.push("2");
sharedList.push("3");
sharedList.push("4");
}
}
【问题讨论】:
-
我想知道我们是否应该开始以不同的方式标记 Angular2“alpha”解决方案,这样现在开始使用它的人就不会感到困惑了。这显然是与“@View”过时的。想法?
-
对我来说很有意义。我自己对 SO 的答案感到困惑,最终意识到它已经很久了
标签: angular