【问题标题】:ngOnInit and data binding not working in ModalView NativeScript AngularngOnInit 和数据绑定在 ModalView NativeScript Angular 中不起作用
【发布时间】:2020-05-03 18:01:37
【问题描述】:

由于缺乏知识,我从 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 属于上层模块AppModule

真正的问题:

模态ShopInfosComponent按意图成功打开,但没有没有数据绑定,实际上ngOnInit没有被调用(与构造函数不同)。

这是模态shop-infos.component.html的内容:

<StackLayout>
    <Label [text]="result"></Label>
    <Label text="Static Text"></Label>
</StackLayout>

我尝试过的

我尝试使用app.component.tsAppModule 中直接打开一个模态框,这很奇怪! 仅当放入由AppModule 导入的另一个模块时才不起作用。

使用的应用模板是来自 Nativescript 的 Navigation Drawer

可能是延迟加载应用路由的问题?

我已经在我的网站上上传了应用图形文档和源代码:https://luiswillnat.eu/stack/nativescript/databinding/

请放心使用,我真的很愿意找到解决方案并从中学习。

【问题讨论】:

标签: angular typescript modal-dialog nativescript nativescript-angular


【解决方案1】:

正如 @Lasanga Guruge 在 cmets 中提到的,它是 current issuenativescript-angular

目前在模式视图中进行数据绑定和 ngOnInit 的解决方法是手动检测更改。

setTimeout(() => {
   this.zone.run(() => this.result = "WORKING")
});

setTimeout(() => {
   this.changeDetectorRef.detectChanges();
});

是目前的解决方法。

【讨论】:

    猜你喜欢
    • 2018-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-19
    • 1970-01-01
    • 2019-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多