我正try 在我的服务中使用来self 的环境的属性终结点.ts:
export const environment = {
production: false,
endpoint: 'http://localhost:3000/api/cabin/'
};
这是我的服务:
import {Injectable} from '@angular/core';
import {environment} from "../../environments/environment";
import {HttpClient} from "@angular/common/http";
import {Cabin} from "../interfaces/cabin";
import {Observable} from "rxjs";
@Injectable({
providedIn: 'root'
})
export class CabinService {`your text`
private myAppUrl: string;
constructor(private http: HttpClient) {
this.myAppUrl = environment.endpoint;
}
getListCabins(): Observable<Cabin[]> {
return this.http.get<Cabin[]>(this.myAppUrl + '/getCabins');
}
}
但当我使用该服务时,我收到以下错误:
[ERROR] TS2339: Property 'endpoint' does not exist on type '{}'. [plugin angular-compiler]
src/app/services/cabin.service.ts:14:32:
14 │ this.myAppUrl = environment.endpoint;
我能做什么?