Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript的实用扩展-Map&;计时器不可用_Javascript_Angular_Reactive Programming_Rxjs - Fatal编程技术网

javascript的实用扩展-Map&;计时器不可用

javascript的实用扩展-Map&;计时器不可用,javascript,angular,reactive-programming,rxjs,Javascript,Angular,Reactive Programming,Rxjs,映射和计时器运算符导入失败,即使它们已被引用。我试着改变导入语句的顺序。我还将扩展升级到“rxjs”:“5.0.0-beta.8” 不知道还有什么可以尝试的,非常感谢您的帮助 import { Component, OnInit } from '@angular/core'; import {WebSocketService} from "../services/WebSocketService"; import { Observable } from 'rxjs/Observable'; im

映射和计时器运算符导入失败,即使它们已被引用。我试着改变导入语句的顺序。我还将扩展升级到“rxjs”:“5.0.0-beta.8”

不知道还有什么可以尝试的,非常感谢您的帮助

import { Component, OnInit } from '@angular/core';
import {WebSocketService} from "../services/WebSocketService";
import { Observable } from 'rxjs/Observable';
import 'rxjs/Rx';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/timer';


@Component({
  selector: 'my-home',
  providers: [WebSocketService],
  template: require('./home.component.html'),
  styles: [require('./home.component.scss')]
})
export class HomeComponent implements OnInit {

  constructor(private websocketservice:WebSocketService) {

  }

  ngOnInit() {
    var  clientId = 10;
    console.log('Hello Home');
    let res;


    return Observable.create((observer) => {
      let subscription = this.websocketservice
          .map(data => res)
          .subscribe(observer);

      return () => {
        subscription.unsubscribe();
      };

    }).retryWhen((errors) => {
      return Observable.timer(3000);
    });

  }

}

我想你还不明白
可观察物是如何工作的。您的
websocketservice
是一个类,您不能在其上调用
.map
——您必须从该类调用一个函数,该函数返回一个
可观察的
。e、 g.:
let subscription=this.websocketservice.getData().map(res=>res.json()).subscription((data)=>{/*code here*/})我认为您不了解
可观察对象是如何工作的。您的
websocketservice
是一个类,您不能在其上调用
.map
——您必须从该类调用一个函数,该函数返回一个
可观察的
。e、 g.:
let subscription=this.websocketservice.getData().map(res=>res.json()).subscription((data)=>{/*code here*/})