【发布时间】: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.ts 在AppModule 中直接打开一个模态框,这很奇怪!
仅当放入由AppModule 导入的另一个模块时才不起作用。
使用的应用模板是来自 Nativescript 的 Navigation Drawer。
可能是延迟加载应用路由的问题?
我已经在我的网站上上传了应用图形文档和源代码:https://luiswillnat.eu/stack/nativescript/databinding/
请放心使用,我真的很愿意找到解决方案并从中学习。
【问题讨论】:
-
尝试手动运行 changeDetection(解决方法)。这可能有助于了解正在发生的事情。 github.com/NativeScript/nativescript-angular/issues/…
-
我看过那个讨论,似乎来自那里,代码终于可以工作了,非常感谢:D!
标签: angular typescript modal-dialog nativescript nativescript-angular