Angular 中未定义输入
Input is not defined in Angular
我想使用 ngTemplate 实现一些东西,我正在关注 this example。
添加@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>;
}
保存后,它会在控制台中显示此错误消息:
my.component.ts:13 Uncaught ReferenceError: Input is not defined
at Module../src/app/my/my.component.ts (my.component.ts:13)
为什么会发生这种情况,如何解决?我什至在 their github 项目上找到了文件,但仍然不知道。可能是个问题,因为我使用的是 Angular 8?
您需要添加导入
import { Component, Input } from '@angular/core';
我想使用 ngTemplate 实现一些东西,我正在关注 this example。
添加@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>;
}
保存后,它会在控制台中显示此错误消息:
my.component.ts:13 Uncaught ReferenceError: Input is not defined at Module../src/app/my/my.component.ts (my.component.ts:13)
为什么会发生这种情况,如何解决?我什至在 their github 项目上找到了文件,但仍然不知道。可能是个问题,因为我使用的是 Angular 8?
您需要添加导入
import { Component, Input } from '@angular/core';