當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。