为什么会给出 nullinjectionError?

问题描述 投票:0回答:1

我很确定这段代码之前可以工作,但现在自上次角度更新以来它不再工作。

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))
  }
}

我尝试了一些其他的依赖实现方法,但没有成功:(

angular dependency-injection angular16
1个回答
0
投票

您可能缺少

HttpClientModule
中的
NgModule
或应用程序根目录下的提供程序配置中的
provideHttpClient
提供程序。

© www.soinside.com 2019 - 2024. All rights reserved.