问题描述:Angular解析器未解析?
解决方法:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [
BrowserModule,
FormsModule
],
// ...
})
export class AppModule { }
例如,使用*ngFor指令来循环渲染一个数组的元素:
- {{ item }}
或者,使用{{}}语法来插入组件中的属性值:
用户名:{{ user.name }}
例如,定义一个自定义的HelloDirective指令:
import { Directive, ElementRef } from '@angular/core';
@Directive({
selector: '[appHello]'
})
export class HelloDirective {
constructor(private el: ElementRef) {
el.nativeElement.innerText = 'Hello!';
}
}
然后,在模板中使用该指令:
确保在NgModule的declarations数组中导入了该指令:
@NgModule({
declarations: [
HelloDirective
],
// ...
})
export class AppModule { }
运行以下命令重新构建应用程序:
ng build
然后重新启动应用程序。
希望以上解决方法能够帮助您解决Angular解析器未解析的问题。