Ionic 离子Angular 错误错误:未被捕获的(在承诺中):错误:参数数组必须有参数,错误:参数数组必须有参数

dddzy1tm  于 2022-12-09  发布在  Ionic
关注(0)|答案(1)|浏览(145)

我正在进行一个离子和Angular 项目。在组件中注入服务时遇到意外错误。

研讨会页面

import { Component, OnInit } from '@angular/core';
import { RegisterService } from '.././register.service';
@Component({
  selector: 'app-workshop',
  templateUrl: './workshop.page.html',
  styleUrls: ['./workshop.page.scss'],
})
export class WorkshopPage implements OnInit {
  name:string;
  phone:string;
  time:string;
  address:string;
  course:string;
  constructor(private rService:RegisterService) { }
  ngOnInit() {
  }
  public open() {
    this.rService.sendData('hello').subscribe(
      response => console.log(response),
      error => console.log(error)
    );
  }
}

错误

core.js:15724 ERROR Error: Uncaught (in promise): Error: Arguments array must have arguments.
Error: Arguments array must have arguments.
    at injectArgs (core.js:1806)
    at core.js:15519
    at _callFactory (core.js:21280)
    at _createProviderInstance (core.js:21238)
    at resolveNgModuleDep (core.js:21213)
    at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:21907)
    at resolveNgModuleDep (core.js:21218)
    at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:21907)
    at resolveDep (core.js:22278)
    at createClass (core.js:22150)
    at resolvePromise (zone.js:831)
    at resolvePromise (zone.js:788)
    at zone.js:892
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
    at Object.onInvokeTask (core.js:17290)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
    at drainMicroTaskQueue (zone.js:601)

服务

import { Injectable } from '@angular/core';
import { HttpClientModule }    from '@angular/common/http';
@Injectable({
  providedIn: 'root'
})
export class RegisterService {
  _url = 'http://localhost/data.php';
  constructor(private http: HttpClient) { }
  sendData(userData) {
      return this.http.post<any>(this._url, userData); 
  }
}
wwtsj6pe

wwtsj6pe1#

只需导入HttpClient而不是setvice.ts中的HttpClientModule,它应该如下所示:

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

并确保HttpClientModule导入到app.module.ts文件中

相关问题