![](/img/trans.png)
[英]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.