有没有办法等待组件初始化?
@Component(
selector: "my-component",
templateUrl: 'component/my.html',
useShadowDom: false,
publishAs: "ctrl"
)
class MyComponent {
@NgAttr('foo')
String foo;
}
@NgAttr('bar')
String bar;
}
MyComponent(){
print(foo);
print(bar);
}
}
用法:
<my-component foo="bar" bar="baz"></my-component>
当我像这样使用组件时,构造函数打印:null, null
我可以为 foo 和 bar 编写一个 setter ,并检查每个设置是否都已设置。但如果没有提供任何值..我的 init 永远不会被解雇。
我是否必须实现一个提供 init 方法或其他方法的接口(interface)?
最佳答案
与此处所示的相同Connecting 2 controllers and have access to the first controllers propertie in the second controller
实现AttachAware
接口(interface)。在构造元素之前无法设置实例的值,因此在执行构造函数时没有机会从外部设置字段。
关于dart - 角 Dart 组件初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26301670/