Angular Ngonit和数据绑定在ModalView NativeScript中不起作用
我从2天开始真诚地搜索,并试图解决由于缺乏知识而导致的问题。我最近开始使用Nativescript,我是Angular的中级用户 问题Angular Ngonit和数据绑定在ModalView NativeScript中不起作用,angular,typescript,modal-dialog,nativescript,nativescript-angular,Angular,Typescript,Modal Dialog,Nativescript,Nativescript Angular,我从2天开始真诚地搜索,并试图解决由于缺乏知识而导致的问题。我最近开始使用Nativescript,我是Angular的中级用户 问题 我正试图在我的map.component.ts中打开模式ShopInfosComponent: ShopInfosComponent属于BrowseModule,我知道我需要将其添加到该模块中 @NgModule({ imports: [ NativeScriptCommonModule, BrowseRoutingM
- 我正试图在我的
中打开模式map.component.ts
:ShopInfosComponent
ShopInfosComponent
属于BrowseModule
,我知道我需要将其添加到该模块中
@NgModule({
imports: [
NativeScriptCommonModule,
BrowseRoutingModule,
],
declarations: [
BrowseComponent,
MapComponent,
ShopInfosComponent
],
entryComponents: [ShopInfosComponent]
})
浏览器模块属于上层模块AppModule
真正的问题:
模式ShopInfosComponent
按预期成功打开,但没有数据绑定,实际上ngOnInit
未被调用(与构造函数不同)
这是modalshop infos.component.html
的内容:
<StackLayout>
<Label [text]="result"></Label>
<Label text="Static Text"></Label>
</StackLayout>
我试过的
我试着用app.component.ts
直接在AppModule
中打开一个模态,它工作起来很奇怪!
只有当放入另一个由AppModule
导入的模块时,它才不起作用
使用的应用程序模板是来自Nativescript的
也许是延迟加载应用程序路由的问题
我已将应用程序图形文档和源代码上载到我的网站:
请随意使用,我真的很愿意找到解决方案并从中学习
正如@Lasanga Guruge在评论中提到的,它是一个
nativescript angular
在模态视图中使用数据绑定和ngOnInit的当前解决方法是手动检测更改
setTimeout(() => {
this.zone.run(() => this.result = "WORKING")
});
或
是目前的解决办法。试着手动运行changeDetection(解决办法)。这可能有助于了解正在发生的事情。我已经看到了讨论,似乎来自那里,代码终于工作了,非常感谢:D!
setTimeout(() => {
this.zone.run(() => this.result = "WORKING")
});
setTimeout(() => {
this.changeDetectorRef.detectChanges();
});