Angular 中未定义输入

Leo*_*ssi -4 javascript input ng-template angular

我想使用 ngTemplate 实现一些东西,并且我正在遵循这个示例

添加@input 时出现我面临的问题:

import { Component, OnInit, TemplateRef } from '@angular/core';

@Component({
  selector: 'app-my',
  templateUrl: './my.component.html',
  styleUrls: ['./my.component.css']
})


export class MyComponent implements OnInit {
   ...
   @Input() headingTemplate: TemplateRef<any>; 

}
Run Code Online (Sandbox Code Playgroud)

保存后,它会在控制台中显示以下错误消息:

my.component.ts:13 Uncaught ReferenceError: 输入未在模块中定义../src/app/my/my.component.ts (my.component.ts:13)

为什么会发生这种情况以及如何解决?我什至在他们的 github项目上找到了该文件,但仍然不知道。因为我使用的是 Angular 8,所以可能会出现问题吗?

Saj*_*ran 5

您需要添加导入

import { Component, Input } from '@angular/core';
Run Code Online (Sandbox Code Playgroud)