当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Observable.subscribe方法代码示例

本文整理汇总了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;
    });
  }
开发者ID:clbond,项目名称:ng2-redux,代码行数:14,代码来源:search.component.ts

示例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);

        
        
        
    }
开发者ID:chuckjaz,项目名称:ames,代码行数:59,代码来源:auth.service.ts

示例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
    }
开发者ID:z-bit,项目名称:book,代码行数:8,代码来源:counter.component.ts

示例4: Observable

 return new Observable(observer => {
       this.txnDetail$.subscribe(dtl => {
          if(dtl.txnDtl.isLoadingSuccess){
            observer.next(dtl);
            observer.complete();
          }
      })
 });
开发者ID:bbachi,项目名称:Angular5Sample,代码行数:8,代码来源:txndetail.resolver.ts

示例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());
         });
     });
 }
开发者ID:raof01,项目名称:utilities,代码行数:8,代码来源:db.service.ts

示例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);
    });
  }
开发者ID:kasperbfrank,项目名称:angular2-redux-starter,代码行数:9,代码来源:items.component.ts

示例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));
 }
开发者ID:xmlking,项目名称:WearableHub,代码行数:10,代码来源:pokemon-detail.component.ts

示例8: tick

export function nextFrom<T>(op: Observable<T>): T | undefined {

    let result: T | undefined = undefined;

    op.subscribe(res => result = res);

    tick();

    return result;
}
开发者ID:surol,项目名称:ng2-rike,代码行数:10,代码来源:rike.spec.ts

示例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);
        }
      });
    });

  }
开发者ID:dimapod,项目名称:xc-dashboard,代码行数:20,代码来源:hot-deployment.component.ts

示例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));
  }
开发者ID:JayKan,项目名称:angular2-observables,代码行数:12,代码来源:weather-panel.component.ts


注:本文中的rxjs/Rx.Observable.subscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。