小编Efi*_*sky的帖子

似乎无法在 Observable 上使用“first()”(Angular 中的 rxjs)

我在 RXJS 中读到了这个很棒的功能,理论上它允许我只订阅一个响应,但似乎无法实现它。相反,我收到此错误,

“'Observable' 类型不存在属性 'first'。”

尽管我只是从现有示例中复制粘贴。这是我的代码:

implementHash( token ){
    console.log('trying to implement hash', token);
    const req = this.http.get('http://localhost:3003/token/' + token );
    const sub = req
        //.first()
        .subscribe( res =>{
            sub.unsubscribe; // trying to avoid this line
    });
};
Run Code Online (Sandbox Code Playgroud)

subscribe rxjs angular

4
推荐指数
1
解决办法
1339
查看次数

Angular,如何在生产环境和开发环境之间切换?

我有一个大型 Angular 应用程序,在开发中仍然需要,但已经准备好在生产中使用,我想通过简单的更改来在状态之间切换

isProduction: boolean = false
Run Code Online (Sandbox Code Playgroud)

为了正确,我通过制作 apiHelperService 来做到这一点,这只是普通的服务,它对于大多数应用程序都可以正常工作:

import {Injectable} from "@angular/core";
import {Response, Http, Headers, RequestOptions} from "@angular/http";
import {Observable} from "rxjs/Observable";

@Injectable()
export class ApiHelperService {
  productionURL: string = 'http://35.203.121.40';
  developmentURL: string = 'http://10.25.37.523';
  serverUrl: string;
  apiPort: string = ':3000/';
  socketPort: string = ':2000/';
  isProductionMode: boolean = false;


  constructor() {
    this.serverUrl = this.isProductionMode ? this.productionURL : this.developmentURL;
  }

  getApiURL(): string {
    return this.serverUrl + this.apiPort;
  }

  getSocketUrl(): string {
    return this.serverUrl + this.socketPort;
  }
  getApiIp(): string …
Run Code Online (Sandbox Code Playgroud)

environment production angular

4
推荐指数
1
解决办法
7815
查看次数

标签 统计

angular ×2

environment ×1

production ×1

rxjs ×1

subscribe ×1