相关疑难解决方法(0)

Angular 2 - 在调用方法之前使用其他服务的服务

我有这种情况.

backend.json

{
"devServer": "http://server1/'",
"proServer" : "http://server2/'",
"use" :  "devServer"
}
Run Code Online (Sandbox Code Playgroud)

global.service.ts

import {Injectable} from '@angular/core';
import {Http, HTTP_PROVIDERS, Response, RequestOptions, URLSearchParams} from '@angular/http';
@Injectable()
export class GlobalService {
constructor(private _http: Http){}
getBackendServer(){
    return this.server = this._http.get('./backend.json')
        .map((res:Response) => res.json())
}
}
Run Code Online (Sandbox Code Playgroud)

我还有其他服务:search.service.ts

import {Injectable} from '@angular/core';
import {Http, HTTP_PROVIDERS, Response, RequestOptions, URLSearchParams} from '@angular/http';
import {GlobalService} from '../services/global.service';
import 'rxjs/add/operator/map';
@Injectable()
export class SearchService {
server;
constructor( private _http: Http, private gs: GlobalService ) {
    this.server = gs.getBackendServer().subscribe( …
Run Code Online (Sandbox Code Playgroud)

angular2-services angular

2
推荐指数
1
解决办法
1973
查看次数

标签 统计

angular ×1

angular2-services ×1