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


TypeScript Observable.empty方法代码示例

本文整理汇总了TypeScript中rxjs/Rx.Observable.empty方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.empty方法的具体用法?TypeScript Observable.empty怎么用?TypeScript Observable.empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rxjs/Rx.Observable的用法示例。


在下文中一共展示了Observable.empty方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1:

 return observable.catch((err: any): any => {
   console.log(err);
   if (err.status === 400 || err.status === 401 || err.status === 422) {
     console.log("Notifying...");
     console.log(err.json());
     this.growlMessageService.notifyError(err.json());
     return Observable.empty();
   }
   else {
     console.log("Redirecting...");
     this.router.navigate(['/error-page']);
     return Observable.empty();
   }
 })
开发者ID:NahuelOlgiati,项目名称:ng2-authentication,代码行数:14,代码来源:custom-http.http.ts

示例2: createLesson

  createLesson(name, context){

    if(!name || !context){
      let empty_observable = Observable.empty();
      console.log("no name or no context");
      return empty_observable;
    }

    let lesson_json = {name: name, context: context};
    let lesson_str = JSON.stringify(lesson_json); 
    let headers = new Headers({'Content-Type': 'application/json'});
    let options = new RequestOptions({headers: headers})
    const network$ = this.http.post('http://cxense.webdemo.dac.co.jp:3000/test/lesson', lesson_json, options)
                        .cache(1);
/*
 ここで、network$は、serviceとcomponentの二ヶ所でsubscribeしているので、
 二回PostRequesstが呼ばれてしまう。
 cache オペレータを用いると、二度の無駄なPostRequestは実行されず、一回になる。
 ただし、Subscribe後に実行されるnextとcompleteは両方ともよばれる。
*/ 
    network$.subscribe(
      () =>{console.log("create lesson succeed : service")},
      (error) => {console.log("create lesson error" + error)},
      ()=>{console.log("create lesson complete: service")}
    )
    return network$;
  }
开发者ID:morninng,项目名称:angular_universisty_rxjs,代码行数:27,代码来源:lessons.service.ts

示例3: handleResponse

    private handleResponse( res: Response ) {
        console.log( "handleResponse: " );
        // console.log( "handleResponse: " + res.toString() );
        var json = res.json();

        // console.log( "jsonResponse: " + JSON.stringify( json ) );

        // console.log( "Checking errors" );
        if ( json.actionErrors && Object.keys( json.actionErrors ).length > 0 ) {
            console.log( "has Errors!!!" );
            throw res;
        }

        // console.log( "Checking login" );
        if ( json.responseCode && json.responseCode == "login" ) {
            console.log( "Needs login!!!" );
            this.router.navigate( ['/login'] );

            return Observable.empty();
        }

        // console.log( "All OK" );

        return res;
    }
开发者ID:xeredi,项目名称:portico,代码行数:25,代码来源:http.interceptor.ts

示例4:

 .map((params: Params): Observable<PypiPackage[]> => {
   const queryPackages = params['packages'];
   if (queryPackages) {
     return this._packageService.getPackages(queryPackages);
   } else {
     return Observable.empty();
   }
 })
开发者ID:gabrielaraujof,项目名称:pypicompare,代码行数:8,代码来源:comparison.component.ts

示例5:

 .catch((err: any): any => {
     if (err.status === 400 || err.status === 422) {
         return Observable.throw(err);
     } else {
         //this.errorService.notifyError(err);
         return Observable.empty();
     }
 })
开发者ID:squadwuschel,项目名称:Angular2Introduction,代码行数:8,代码来源:customHttp.ts

示例6: walkHelper

 .concatMap(obj =>
   obj.stats.isDirectory()
     ? (
       dirBlacklist.has(obj.name)
         ? Observable.empty()
         : walkHelper(obj.path, dirBlacklist)
     )
     : Observable.of(obj)
开发者ID:joshuaeilers,项目名称:file-walker-rx,代码行数:8,代码来源:fs-walker.ts

示例7:

 return observable.catch((err, source) => {
   if (err.status  === 401 && !_.endsWith(err.url, '/login')) {
       this._router.navigate(['login']);
       return Observable.empty(null);
     } else {
       return Observable.throw(err);
   }
 });
开发者ID:divino,项目名称:marklogic-data-hub,代码行数:8,代码来源:http.ts

示例8:

 }).catch(err => {
   if (err.status == 401) { // Unauthorized i.e. not logged in
     console.info('No valid token, redirecting to login', err.json());
   } else {
     console.error('resume error', err);
   }
   this.router.navigate(['login']);
   return Observable.empty();
 }).finally(resolveDone);
开发者ID:StudioProcess,项目名称:imagetool,代码行数:9,代码来源:resume.service.ts

示例9: it

  it('should mirror source if durations are Observable.empty()', () => {
    const e1 =   hot('abcdefabcdefabcdefabcdefa|');
    const e1subs =   '^                        !';
    const e2 =  Rx.Observable.empty();
    const expected = 'abcdefabcdefabcdefabcdefa|';

    const result = e1.audit(() => e2);

    expectObservable(result).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });
开发者ID:jayphelps,项目名称:rxjs,代码行数:11,代码来源:audit-spec.ts

示例10: deleteLesson

  deleteLesson(name_arr : string[]){

    if(!Array.isArray(name_arr) || name_arr.length == 0){
      let empty_observable = Observable.empty();
      console.log("no item to delete");
      return empty_observable;
    }


    let delete_lesson_str = JSON.stringify(name_arr); 
    let headers = new Headers({'Content-Type': 'application/json'});
    let options = new RequestOptions({headers: headers});
    let req_url = "http://cxense.webdemo.dac.co.jp:3000/test/lesson?name_arr=" + delete_lesson_str;

    const network$ = this.http.delete(req_url, options).cache(1);;
    network$.subscribe(
      () =>{console.log("delete lesson succeed : service")},
      (error)=>{console.log("delete lesson error", error)},
      ()=>{console.log("delete lesson complete: service")}
    )
    return network$;
  }
开发者ID:morninng,项目名称:angular_universisty_rxjs,代码行数:22,代码来源:lessons.service.ts


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