我很确定这段代码之前可以工作,但现在自上次角度更新以来它不再工作。
import { Inject, Injectable, inject } from '@angular/core';
import { UserModel } from '../Models/UserModel';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable , retry} from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class UserService {
constructor(
private http : HttpClient
){}
rootUrl = ""
Login(email:string , password:string):Observable<number>{
let Param1 = new HttpParams().set("email" , email).append("password" , password)
console.log("These are Params: " + Param1);
return this.http.get<number>(this.rootUrl + "/U/GetUser" , {params:Param1});
}
CreateUser(user:UserModel){
this.http.post(this.rootUrl + "/U/CreateUser" , user).subscribe((res)=>alert("User Created" + user))
}
}
我尝试了一些其他的依赖实现方法,但没有成功:(
您可能缺少
HttpClientModule
中的 NgModule
或应用程序根目录下的提供程序配置中的 provideHttpClient
提供程序。