本文整理汇总了TypeScript中rxjs/Rx.Observable.subscribe方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.subscribe方法的具体用法?TypeScript Observable.subscribe怎么用?TypeScript Observable.subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs/Rx.Observable
的用法示例。
在下文中一共展示了Observable.subscribe方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: ngOnInit
ngOnInit() {
// Exercise the flow where a state change results in a new action.
this.search$.subscribe(keyword => {
if (keyword != '') {
this.actions.fetchResultDispatch(keyword.length)
}
});
// Exercise the flow where you set a member on change manually instead of
// using async pipe.
this.numChars$.subscribe(state => {
this.numChars = state;
});
}
示例2: constructor
constructor(public af: AngularFire, private zone: NgZone, private router : Router) {
this.userData = this.af.auth.flatMap( authState => {
// Overcome angularfire's zone smashing
return zone.run((): Observable<any> => {
if(authState) {
this.updatableUser = af.database.object('/users/'+authState.uid);
return this.updatableUser;
} else {
this.updatableUser = null;
return Observable.of(null);
}
});
}).cache(1);
// Detect missing user data and forward to quick-profile
this.userData.subscribe( authState => {
if(authState != null && !authState.name) {
this.router.navigate(['/profile-short']);
}
});
// isAdmin should be an observable that sends trues of falses as the users gains or loses admin access
// Need to combine two streams. take the stream of auth data, and use it to generate a stream of values
// for the /admin/[userid] and then check to see if the user is an admin
this.isAdmin = this.af.auth.switchMap( authState => {
// Overcome angularfire's zone smashing
return zone.run((): Observable<boolean> => {
if(!authState) {
return Observable.of(false);
} else {
return this.af.database.object('/admin/'+authState.uid)
.catch((a, b) => {
// This permission error means we aren't an admin
return Observable.of(false)
});
}
});
}).map( adminObject =>
(adminObject && adminObject['$value'] === true)
).cache(1);
this.isUser = this.af.auth.map( authState => !!authState).cache(1);
this.uid = this.af.auth.switchMap( authState => {
if(!authState) {
return Observable.of(null);
} else {
return Observable.of(authState.uid);
}
}).cache(1);
}
示例3: inc
inc(){
this.store.dispatch({type: INCREMENT});
console.log('counter$', this.counter$); // object
console.log('counter', this.counter$.destination._value.counter); // value
console.log('store: ', this.store._value.counter); // same value
this.counter$.subscribe(state => console.log('subscribe: ', state));// proper way
}
示例4: Observable
return new Observable(observer => {
this.txnDetail$.subscribe(dtl => {
if(dtl.txnDtl.isLoadingSuccess){
observer.next(dtl);
observer.complete();
}
})
});
示例5: getDbs
public getDbs() {
this.dbConn.subscribe((v: DbConnModel) => {
this.dbRepository.getDbs(v).subscribe((value: Response) => {
this.store.dispatch(this.dbActions.addDbs(value.json()))
this.proxyService.notifyDbs(value.json());
});
});
}
示例6: constructor
constructor(private appStore: AppStoreService, private utils: UtilsService) {
this.items$ = this.appStore.items.items$;
this.appStore.items.selectedItem$
.subscribe((res) => this.selectedItem = res);
this.items$.subscribe(res => {
console.log('items', res);
});
}
示例7: ngOnInit
ngOnInit(): void {
this.pokemon$ = this.store.select<Pokemon>("pokemon", "selectedItem");
this.error$ = this.store.select<any>("pokemon", "error");
// TODO: fix template to use async
this.sub = this.pokemon$.subscribe( (pokemon: Pokemon) => {
this.pokemon = pokemon;
});
const id = this.route.snapshot.params["id"];
this.store.dispatch(this.pokemonActions.getDetail(id));
}
示例8: tick
export function nextFrom<T>(op: Observable<T>): T | undefined {
let result: T | undefined = undefined;
op.subscribe(res => result = res);
tick();
return result;
}
示例9: ngAfterViewInit
ngAfterViewInit() {
this.lamps$.subscribe(lamps => {
lamps.forEach(lamp => {
const lampDirective = this.findLamp(lamp.id);
if (lampDirective) {
lampDirective.changeColor(lamp.color);
}
});
});
this.services$.subscribe(services => {
services.forEach(service => {
const serviceDirective = this.findService(service.id);
if (serviceDirective) {
serviceDirective.handleStatus(service.status, service.version);
}
});
});
}
示例10: ngOnInit
ngOnInit(): void {
const weatherURL = "https://publicdata-weather.firebaseio.com/";
let city = new Firebase(weatherURL).child(this.city);
this.currently = observableFirebaseObject(city.child('currently'));
this.currently.subscribe(res => {
this.current = res;
});
this.hourly = observableFirebaseArray(city.child('hourly/data').limitToLast(10));
}