【发布时间】:2019-05-10 08:41:05
【问题描述】:
所以我试图在一个新模块中创建一个组件,然后在“app”中使用它,但是我收到了这个错误:
Error: Root should be either UIViewController or UIView
这是我的 sample.module.ts:
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
import { NativeScriptCommonModule } from 'nativescript-angular/common';
import { SampleComponent } from './sample/sample.component';
@NgModule({
declarations: [SampleComponent], // <= this is the component I want to use
exports: [SampleComponent],
imports: [
NativeScriptCommonModule
],
schemas: [NO_ERRORS_SCHEMA]
})
export class SampleModule { }
然后是我的示例组件:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'ns-sample',
templateUrl: './sample.component.html',
styleUrls: ['./sample.component.css'],
moduleId: module.id,
})
export class SampleComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
然后在我的应用程序中,我正在像这样导入模块:
imports: [
// ... other modules
SampleModule,
],
当我尝试像这样在 app.component.html 中使用 SampleComponent 选择器时,会触发错误消息:
<ns-sample></ns-sample>
我一直在环顾四周,但我不断发现人们忘记导出模块本身的错误。我已经这样做了,所以我不确定我做错了什么。
所以问题是如何使用在应用程序内部的不同模块中声明的组件?
提前谢谢大家!!
【问题讨论】:
标签: angular nativescript angular-components angular-module