Angular 动态重新加载无法正常工作
我的开发环境:Angular 动态重新加载无法正常工作,angular,angular-cli,livereload,Angular,Angular Cli,Livereload,我的开发环境: 视窗10 Visual Studio代码1.51.1 角度11 节点15.1.0 我正在做一个角度课程,并使用CLI创建了应用程序。我面临的重新加载问题只能通过重新启动服务器来解决(ctrl-c和ng再次服务) app.module.ts: import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppCompo
- 视窗10
- Visual Studio代码1.51.1
- 角度11
- 节点15.1.0
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { ServerComponent } from './server/server.component';
import { FormsModule } from '@angular/forms';
@NgModule({
declarations: [
AppComponent,
ServerComponent
],
imports: [BrowserModule, FormsModule],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
server.component.ts:
import { Component } from '@angular/core';
@Component({
selector: 'app-server',
templateUrl: './server.component.html',
styles: [
`
.online {
color: white;
}
`
]
})
export class ServerComponent {
serverId: number = 10;
serverStatus: string = 'offline';
constructor() {
this.serverStatus = Math.random() > 0.5 ? 'offline' : 'online';
}
getServerStatus() {
return this.serverStatus;
}
getColor() {
return this.serverStatus === 'online' ? 'green' : 'red';
}
}
server.component.html:
<p
[ngStyle]="{ backgroundColor: getColor(), 'font-weight': 'bold' }"
[ngClass]="{ online: serverStatus === 'online' }"
>
Server with ID {{ serverId }} is {{ getServerStatus() }}
</p>
因此,我必须停止服务器并重新启动它。那不是很有成效。。。
我做错了什么
我还可以通过向服务器组件添加角度导入来解决此问题,例如:
import { CommonModule } from '@angular/common';
这会触发重新加载,背景色又恢复了。我也面临这个问题,我认为没有解决办法:(
import { CommonModule } from '@angular/common';