小编ada*_*wak的帖子

如何在rxjs中执行链序列

我想要的是:

this._myService.doSomething().subscribe(result => {
  doSomething()
});
.then( () => dosthelse() )
.then( () => dosanotherthing() )
Run Code Online (Sandbox Code Playgroud)

所以我想链接.然后像承诺一样.我如何在Rxjs中做到这一点?

this._myService.getLoginScreen().subscribe( result => {
      window.location.href = MyService.LOGIN_URL;
      /// I would like to wait for the site to load and alert something from       the url, when I do it here it alerts the old one
    });
   .then (alert(anotherService.partOfTheUrl())


getLoginScreen() {
  return this.http.get(myService.LOGIN_URL)
.flatMap(result => this.changeBrowserUrl())
.subscribe( result => //i want to do sth when the page is loaded//);
}

changeBrowserUrl(): Observable<any> {
return Observable.create( …
Run Code Online (Sandbox Code Playgroud)

javascript http rxjs typescript angular

38
推荐指数
3
解决办法
7万
查看次数

使用打字稿进行地理定位

我有以下代码片段:

pos:number;

getPosition() {
    navigator.geolocation.getCurrentPosition((position) => {

        this.pos = position.coords.latitude;
Run Code Online (Sandbox Code Playgroud)

当我调试时,我在 this.pos 上没有定义,在 position.coords.latitude 上有一些数字

但是当我有以下代码片段时:

pos:any;

getPosition() {
    navigator.geolocation.getCurrentPosition((position) => {

        this.pos = position.coords.latitude;
Run Code Online (Sandbox Code Playgroud)

然后设置了 this.pos。为什么会有这样的行为?

geolocation typescript

5
推荐指数
1
解决办法
9011
查看次数

可以观察到,我做得对吗?

我有这项服务:

 getPosition(): Observable<Object> {
    return Observable.create(observer => {
        navigator.geolocation.watchPosition((pos: Position) => {
            observer.next(pos);
            observer.complete();
        }),
        () => {
            console.log('Position is not available');
        },
        {
            enableHighAccuracy: true
        };
    });
}
Run Code Online (Sandbox Code Playgroud)

我想这样使用它:

this.getLocationService.getPosition().subscribe((pos: Position) => {
        self._latitude = pos.coords.latitude;
        self._longitude = pos.coords.longitude; }
Run Code Online (Sandbox Code Playgroud)

但不幸的是它不起作用.我假设每次位置变化,纬度和长度都会改变.但它不起作用.

javascript geolocation rxjs typescript angular

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

从承诺中得到一个数字

我有:

 getZoom(): Promise<number> {
    return this._googleMapsApi.getMap().then((map:google.maps.Map) => map.getZoom());
}
Run Code Online (Sandbox Code Playgroud)

我想检查缩放级别:

private onStartZoomEvent() {
    console.log('on start zoom');
    if (this._mapController.getZoom().valueOf() !== 12) {
    this.disableGeolocationButton();
    this._eventAggregator.trigger(this.disableGeolocation);
     }
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

javascript promise typescript angular

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

标签 统计

typescript ×4

angular ×3

javascript ×3

geolocation ×2

rxjs ×2

http ×1

promise ×1