如果我有一个孩子控制(或在这种情况下是孙子),看起来像这样:
<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)
我本来期望regionId
在attached
发生之前是1。这是预期的行为吗?
该变量应填入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
是我绑定它的价值。