小编Vio*_*lla的帖子

Nullinjectorerror:没有 httpclient 的提供者!没有 app.module.ts

我正在尝试使用 HttpClient 读取 Ionic Angular 中的 JSON,但收到此错误“nullinjectorerror:没有 httpclient 的提供程序!”。

问题是最新版本的 Angular 不会生成 app.module.ts。

我的代码:

import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { IonicModule } from '@ionic/angular';

import { HttpClient } from '@angular/common/http';
import { map } from 'rxjs';

@Component({
  selector: 'app-ficha-evento',
  templateUrl: './ficha-evento.page.html',
  styleUrls: ['./ficha-evento.page.scss'],
  standalone: true,
  imports: [IonicModule, CommonModule, FormsModule]
})
export class FichaEventoPage implements OnInit {

  event:any=[];

  constructor(private http: HttpClient) { }

  ngOnInit() {
    this.getEvnt().subscribe(res=>{ …
Run Code Online (Sandbox Code Playgroud)

httpclient ionic-framework angular ionic6

9
推荐指数
2
解决办法
8909
查看次数

标签 统计

angular ×1

httpclient ×1

ionic-framework ×1

ionic6 ×1