您好,我正在从事离子和角度项目,但在向我的组件中注入服务时遇到了意外错误,我在互联网上搜索并尝试了几种解决方案,但对我不起作用我对角度和离子是陌生的,请帮助我做错了。谢谢
WorkshopPage
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);
}
}
答案 0 :(得分:0)
只需在setvice.ts中导入HttpClient而不是HttpClientModule 应该是这样的:
Context context = this;
并确保在app.module.ts文件中导入了HttpClientModule