如果我有一个子控件(或本例中的孙子控件),如下所示:
<my-control region-id.two-way="location.regionId"></my-control>我什么时候可以期望regionId可用?文档听起来像是绑定,然后附加发生,所以不应该在附加发生之前设置regionId吗?
我已经向bind、attached和regionIdChanged事件添加了一些日志记录,并查看控制台,我看到
bind
attached
regionIdChange to null from undefined (default value in a dropdown)
regionIdChange to 1 from null (1 is the actual value)在attached发生之前,我期望regionId是1。这是预期的行为吗?
发布于 2018-08-17 14:56:28
该变量应在bind()阶段中填写。
如果将日志记录添加到每个阶段:
export class Child {
@bindable()
public field: string;
constructor() {
console.info("constructor: ", this.field);
}
bind() {
console.info("bind: ", this.field);
}
attached() {
console.info("attached: ", this.field);
}
}它会生成以下日志输出:
constructor: undefined
bind: test
attached: test其中test是我将其绑定到的值。
https://stackoverflow.com/questions/51885323
复制相似问题