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


TypeScript Observable.subscribe方法代码示例

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


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

示例1: ngOnInit

 ngOnInit() {
   this.appMode$.subscribe((mode: AppModes) => {
     this.show = mode !== AppModes.Add && mode !== AppModes.Edit;
   });
 }
开发者ID:christinakayastha,项目名称:parkabler,代码行数:5,代码来源:add-edit-button.component.ts

示例2: subscribeToSaveResponse

 private subscribeToSaveResponse(result: Observable<HttpResponse<IBankAccount>>) {
     result.subscribe((res: HttpResponse<IBankAccount>) => this.onSaveSuccess(), (res: HttpErrorResponse) => this.onSaveError());
 }
开发者ID:PierreBesson,项目名称:jhipster-sample-app,代码行数:3,代码来源:bank-account-update.component.ts

示例3: expect

 expect(() => {
   window.subscribe();
 }).to.throw(ObjectUnsubscribedError);
开发者ID:DallanQ,项目名称:rxjs,代码行数:3,代码来源:windowToggle-spec.ts

示例4: setTimeout

setTimeout(() => {
  sequence.subscribe({
    next(num) { console.log('2nd subscribe: ' + num); },
    complete() { console.log('2nd sequence finished.'); }
  });
}, 500);
开发者ID:DallanQ,项目名称:rxjs,代码行数:6,代码来源:multicasting.ts

示例5: filter

export const findCodeViews = (codeHost: CodeHost, watchChildrenModifications = true) => (
    containers: Observable<Element>
) => {
    const codeViewsFromList: Observable<ResolvedCodeView> = containers.pipe(
        filter(() => !!codeHost.codeViews),
        mergeMap(container =>
            from(codeHost.codeViews!).pipe(
                map(({ selector, ...info }) => ({
                    info,
                    matches: container.querySelectorAll<HTMLElement>(selector),
                }))
            )
        ),
        mergeMap(({ info, matches }) =>
            of(...matches).pipe(
                map(codeView => ({
                    ...info,
                    codeView,
                }))
            )
        )
    )

    const codeViewsFromResolver: Observable<ResolvedCodeView> = containers.pipe(
        filter(() => !!codeHost.codeViewResolver),
        map(container => ({
            resolveCodeView: codeHost.codeViewResolver!.resolveCodeView,
            matches: container.querySelectorAll<HTMLElement>(codeHost.codeViewResolver!.selector),
        })),
        mergeMap(({ resolveCodeView, matches }) =>
            of(...matches).pipe(
                map(codeView => ({
                    resolved: resolveCodeView(codeView),
                    codeView,
                })),
                filter(propertyIsDefined('resolved')),
                map(({ resolved, ...rest }) => ({
                    ...resolved,
                    ...rest,
                }))
            )
        )
    )

    const obs = [codeViewsFromList, codeViewsFromResolver]

    if (watchChildrenModifications) {
        const possibleLazilyLoadedContainers = new Subject<HTMLElement>()

        const mutationObserver = new MutationObserver(mutations => {
            for (const mutation of mutations) {
                if (mutation.type === 'childList' && mutation.target instanceof HTMLElement) {
                    const { target } = mutation

                    possibleLazilyLoadedContainers.next(target)
                }
            }
        })

        containers.subscribe(container =>
            mutationObserver.observe(container, {
                childList: true,
                subtree: true,
            })
        )

        const lazilyLoadedCodeViews = possibleLazilyLoadedContainers.pipe(findCodeViews(codeHost, false))

        obs.push(lazilyLoadedCodeViews)
    }

    return merge(...obs).pipe(
        emitWhenIntersecting(250),
        filter(({ codeView }) => !codeView.classList.contains('sg-mounted'))
    )
}
开发者ID:JoYiRis,项目名称:sourcegraph,代码行数:76,代码来源:code_views.ts

示例6: ngOnInit

 ngOnInit(): void {
   this.counter$.subscribe((state: CounterModel): void => {
     this.c$ = { ...state };
   });
 }
开发者ID:Shyam-Chen,项目名称:Angular2TS-Starter-Kit,代码行数:5,代码来源:counter.component.ts

示例7: subscribeToSaveResponse

 private subscribeToSaveResponse(result: Observable<Customer>) {
     result.subscribe(() => this.onSaveSuccess(), () => this.onSaveError());
 }
开发者ID:dubrovsky,项目名称:Sakila,代码行数:3,代码来源:customer-detail.component.ts

示例8:

 * - the execution can be disposed.
 */

// how to create a new Observable:
//
// the constructor argument is a function that is called when the Observable is
// initially subscribed to.
// 
// This function represents an Observable execution that happens for any
// Observer/Consumer that subscribes. 
// The subscriber is an object that has 3 methods:
//
// - `next` can be called to emit new values that will be consumed.
// - `error` can be called to raise an error.
// - `complete` can be called to notify of a successful completion.

const o$ = new Observable<number>(subscriber => subscriber.next(1));

// creates a Subscription: an "execution environment" for the observer/consumer.
// the observable will start emitting values only after a subscription.
const subscription = o$.subscribe(v => console.log("subscriber: " + v));

console.log(`is the observable active? ${!subscription.closed}`);

// the subscription can be used to cancel the execution, more on this later on.

// Output:
//
// subscriber: 1
// is the observable active? true
开发者ID:AGiorgetti,项目名称:rxjs101,代码行数:30,代码来源:01-Create_an_Observable.ts

示例9:

 this.productSearchListUpdateService.change.subscribe((result: Observable<Object>) => {
   this.searchTerm = this.productSearchListUpdateService.searchTerm;
   result.subscribe(res => {
     this.productList = res.results;
   });
 });
开发者ID:antonmr,项目名称:UNISUAM,代码行数:6,代码来源:product-list.component.ts

示例10:

 /**
  * Make Cold observable to Hot observable
  * 
  * On caller function will not need to make ".subscribe(...)" to execute procedure
  * 
  * @param cold Observable
  */
 public static makeHot<T>(cold: Observable<T>) {
   const subject = new Subject<T>();
   cold.subscribe(subject);
   return new Observable<T>((observer: any) => subject.subscribe(observer));
 }
开发者ID:PoompisekK,项目名称:myWork,代码行数:12,代码来源:rxjs.util.ts


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