簡體   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