我似乎无法让这个solution为我的代码工作。这是我的原始代码,没有间隔。但不幸的是,它提出了太多的要求。
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
constructor(private http: HttpClient) {}
ngOnInit() {
}
getWeather() {
this.response = this.http.get<Weather>(this.serviceUrl );
this.response.subscribe(
results => {
this.weathers = results.properties.periods;
console.log('this.weather ====> ', this.weathers);
});
}
}但是现在我在添加interval时出现了错误:
错误TypeError:无法读取未定义属性的“间隔”
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
constructor(private http: HttpClient) {}
ngOnInit() {
}
getWeather() {
this.response = this.http.get<Weather>(this.serviceUrl );
this.response.Observable.interval(60000).subscribe(
results => {
this.weathers = results.properties.periods;
console.log('this.weather ====> ', this.weathers);
});
}
}我使用了下面的代码,它不会给我任何错误,但是它仍然进入无限响应,好像间隔没有影响一样。
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { interval } from 'rxjs';
import { take } from 'rxjs/operators';
import { Subject } from 'rxjs';
takeFourNumbers = interval(50000).pipe(take(4));
constructor(private http: HttpClient) {}
ngOnInit() {
}
getWeather() {
this.response = this.http.get<Weather>(this.serviceUrl );
this.response.subscribe(
results => {
this.weathers = results.properties.periods;
console.log('this.weather ====> ', this.weathers);
this.takeFourNumbers.subscribe(x => console.log('Next: ', x));
});
}
}最近有什么东西改变了角6+,旧的解决方案不再起作用了?我对角质还不熟悉。
发布于 2019-03-20 06:07:50
尝试如下:
import { interval } from 'rxjs';
import { map } from 'rxjs/operators'
interval(50000).pipe(
map((x) => { /* your code here */ })
);https://stackoverflow.com/questions/55252514
复制相似问题