1,在service中实例化HttpClient后,界面显示空白,原因在app.modules中没有引入相应的模块
import { Injectable } from '@angular/core';
import {HttpClient} from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class UserService {
constructor(private httpClient: HttpClient) { } //因为这句,本来显示的页面,变成了空白
/*
public login(username: string, password: string): any{
const body = {
username,
password
};
// return this.httpClient.post('http://192.168.1.104:8080/login', body);
return null;
}*/
}
解决如下:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { LoginCompone