且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法使用打字稿向我的 angular 2 应用程序添加新组件

更新时间:2023-11-22 17:09:22

错误本身表明指令不存在于 组件,因为它已被弃用.试试下面显示的代码,

Error itself says that directives doesn't exist in Component as it has been deprecated. try this code shown below,

import { MyComponentComponent } from './my-component/my-component.component'
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';

@NgModule({
   ...
   ...
   declarations:[AppComponent,MyComponentComponent], //<---need to declare 
   schemas:     [CUSTOM_ELEMENTS_SCHEMA]             //<---added this line
})

并从 AppComponent 中删除 directives:[MyComponentComponent].