我想要的是:
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) 我有以下代码片段:
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。为什么会有这样的行为?
我有这项服务:
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)
但不幸的是它不起作用.我假设每次位置变化,纬度和长度都会改变.但它不起作用.
我有:
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)
我究竟做错了什么?