[英]Angular 2+: data binding using Subjects is not working in ngOnInit
[英]ngOnInit and data binding not working in ModalView NativeScript Angular
由于缺乏知识,我从 2 天开始就在真诚地寻找并试图解决这个问题。 我最近开始了 Nativescript,我是 Angular 的中间人。
map.component.ts
ShopInfosComponent
const options: ModalDialogOptions = {
viewContainerRef: this.viewContainerRef,
fullscreen: false,
context: {},
};
this.modalService.showModal(ShopInfosComponent, options);
ShopInfosComponent
属于BrowseModule
我知道我需要将其添加到
@NgModule({
imports: [
NativeScriptCommonModule,
BrowseRoutingModule,
],
declarations: [
BrowseComponent,
MapComponent,
ShopInfosComponent
],
entryComponents: [ShopInfosComponent]
})
BrowseModule 属于上层 Module AppModule
。
模态ShopInfosComponent
成功打开,但没有数据绑定,实际上没有调用ngOnInit
(与构造函数不同)。
这是模式shop-infos.component.html
的内容:
<StackLayout>
<Label [text]="result"></Label>
<Label text="Static Text"></Label>
</StackLayout>
我尝试使用AppModule
在app.component.ts
中直接打开一个模式,这很奇怪! 仅当放入由AppModule
导入的另一个模块时,它才不起作用。
使用的应用程序模板是来自 Nativescript 的Navigation Drawer 。
也许这是延迟加载应用程序路由的问题?
我已经在我的网站上上传了应用程序图形文档和源代码: https://luiswillnat.eu/stack/nativescript/databinding/
请随意使用,我真的很愿意找到解决方案并从中学习。
正如@Lasanga Guruge 在评论中提到的那样,这是nativescript-angular
的当前问题。
当前在模式视图中具有数据绑定和 ngOnInit 的解决方法是手动检测更改。
setTimeout(() => {
this.zone.run(() => this.result = "WORKING")
});
或者
setTimeout(() => {
this.changeDetectorRef.detectChanges();
});
是目前的解决方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.