我会在我的角度应用程序中使用socket.IO,特别是在我的服务中。
我已经在我的后端实现了emit
功能。
这是我的角色逻辑。
import { Injectable } from "@angular/core";
import { NouveauProjet } from "./models/nouveau-projet";
import { HttpClient, HttpResponse } from "@angular/common/http";
import { Observable } from "rxjs/Observable";
import "rxjs/add/operator/map";
import "rxjs/add/operator/catch";
import * as io from "socket.io-client";
@Injectable()
export class AjoutprojService {
socket = io('http://localhost:8081');
apiURL = "http://127.0.0.1:8080/api/proj/projets";
constructor(private http: HttpClient ) {};
this.socket.on('added', function (){
getAllProj(): Observable<NouveauProjet[]> {
return this.http.get<NouveauProjet[]>(
"http://127.0.0.1:8081/api/proj/projets"
);
}
});
getProj(id): Observable<NouveauProjet[]> {
return this.http.get<NouveauProjet[]>(
"http://127.0.0.1:8081/api/proj/nouvProjs/" + id
);
}
addProj(nouveauProjet: NouveauProjet): Observable<any> {
return this.http.post<NouveauProjet[]>(
"http://127.0.0.1:8081/api/proj/projets",
nouveauProjet
);
}
}
我收到此错误:
ERROR in ./src/app/ajoutproj.service.ts
Module parse failed: Unexpected token (42:31)
You may need an appropriate loader to handle this file type.
| this.socket.on('added', function () {
| getAllProj();
| Observable < NouveauProjet[] > {
| return: this.http.get("http://127.0.0.1:8081/api/proj/projets")
| };
在我的组件中使用它时出现相同的错误。