Кажется, что я не могу запустить и запустить мой сервис в angular 6. Я пытаюсь вызвать любую функцию в CoreService, но, похоже, она не работает.
В чем причина?
Ошибка:
error TS2339: Property 'query' does not exist on type 'typeof CoreService'.
Вот где я вызываю функцию CoreService.
import { CoreService} from "./../core.service";
CoreService.query('login','POST',{username: this.username, password: this.password}).takeUntil(this.ngUnsubscribe).subscribe((value) => {
});
А вот мой сервис:
import { throwError as observableThrowError, interval as observableInterval, Observable, Subscription , Subject} from 'rxjs';
import { tap, map } from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { RequestOptions, URLSearchParams } from '@angular/http';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { environment } from './../environments/environment';
import { Router, NavigationEnd, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
@Injectable({providedIn: 'root'})
export class CoreService {
constructor(private http: HttpClient, private router: Router) {}
result = {};
permission = false;
baseurl = environment.apiUrl;
baseapi = this.baseurl + ':3000/api';
options = {withCredentials: true};
query(action,type,postdata) {
// console.log("calling: " + type + " : " + action);
if (type == 'POST') {
return this.http.post(this.baseapi + "/" + action, postdata ,this.options).pipe(
map(result => result),
tap(result => this.result = result),);
} else {
return this.http.get(this.baseapi + "/" + action, this.options).pipe(
map(result => result),
tap(result => this.result = result),);
}
}
performLogin(name: string, password: string) {
var params = new URLSearchParams();
params.append('username', name);
params.append('password', password);
return this.http.post(this.baseapi + '/login/login',params, this.options).pipe(
map(result => result),
tap(result => this.result = result),);
}
}
Что вызывает этопроизойти?