繁体   English   中英

ngOnInit 和数据绑定在 ModalView NativeScript Angular 中不起作用

[英]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>

我试过的

我尝试使用AppModuleapp.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM