當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript NgZone.run方法代碼示例

本文整理匯總了TypeScript中@angular/core.NgZone.run方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript NgZone.run方法的具體用法?TypeScript NgZone.run怎麽用?TypeScript NgZone.run使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@angular/core.NgZone的用法示例。


在下文中一共展示了NgZone.run方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

 .subscribe(isAuthenticated => {
   if (isAuthenticated) {
     this.zone.run(() => this.router.navigate(['/']));
   }
 });
開發者ID:bryant-pham,項目名稱:brograder,代碼行數:5,代碼來源:login.component.ts

示例2: macroTask

 macroTask(() => { _zone.run(() => { scheduleMicroTask(() => { throw exception; }); }); });
開發者ID:DeepanParikh,項目名稱:angular,代碼行數:1,代碼來源:ng_zone_spec.ts

示例3: bootstrap

  /**
   * Bootstrap an AngularJS application from this NgModule
   * @param element the element on which to bootstrap the AngularJS application
   * @param [modules] the AngularJS modules to bootstrap for this application
   * @param [config] optional extra AngularJS bootstrap configuration
   */
  bootstrap(
      element: Element, modules: string[] = [], config?: any /*angular.IAngularBootstrapConfig*/) {
    const INIT_MODULE_NAME = UPGRADE_MODULE_NAME + '.init';

    // Create an ng1 module to bootstrap
    const initModule =
        angular
            .module(INIT_MODULE_NAME, [])

            .value(INJECTOR_KEY, this.injector)

            .config([
              $PROVIDE, $INJECTOR,
              ($provide: angular.IProvideService, $injector: angular.IInjectorService) => {
                if ($injector.has($$TESTABILITY)) {
                  $provide.decorator($$TESTABILITY, [
                    $DELEGATE,
                    (testabilityDelegate: angular.ITestabilityService) => {
                      const originalWhenStable: Function = testabilityDelegate.whenStable;
                      const injector = this.injector;
                      // Cannot use arrow function below because we need the context
                      const newWhenStable = function(callback: Function) {
                        originalWhenStable.call(testabilityDelegate, function() {
                          const ng2Testability: Testability = injector.get(Testability);
                          if (ng2Testability.isStable()) {
                            callback();
                          } else {
                            ng2Testability.whenStable(
                                newWhenStable.bind(testabilityDelegate, callback));
                          }
                        });
                      };

                      testabilityDelegate.whenStable = newWhenStable;
                      return testabilityDelegate;
                    }
                  ]);
                }

                if ($injector.has($INTERVAL)) {
                  $provide.decorator($INTERVAL, [
                    $DELEGATE,
                    (intervalDelegate: angular.IIntervalService) => {
                      // Wrap the $interval service so that setInterval is called outside NgZone,
                      // but the callback is still invoked within it. This is so that $interval
                      // won't block stability, which preserves the behavior from AngularJS.
                      let wrappedInterval =
                          (fn: Function, delay: number, count?: number, invokeApply?: boolean,
                           ...pass: any[]) => {
                            return this.ngZone.runOutsideAngular(() => {
                              return intervalDelegate((...args: any[]) => {
                                // Run callback in the next VM turn - $interval calls
                                // $rootScope.$apply, and running the callback in NgZone will
                                // cause a '$digest already in progress' error if it's in the
                                // same vm turn.
                                setTimeout(() => { this.ngZone.run(() => fn(...args)); });
                              }, delay, count, invokeApply, ...pass);
                            });
                          };

                      (wrappedInterval as any)['cancel'] = intervalDelegate.cancel;
                      return wrappedInterval;
                    }
                  ]);
                }
              }
            ])

            .run([
              $INJECTOR,
              ($injector: angular.IInjectorService) => {
                this.$injector = $injector;

                // Initialize the ng1 $injector provider
                setTempInjectorRef($injector);
                this.injector.get($INJECTOR);

                // Put the injector on the DOM, so that it can be "required"
                angular.element(element).data !(controllerKey(INJECTOR_KEY), this.injector);

                // Wire up the ng1 rootScope to run a digest cycle whenever the zone settles
                // We need to do this in the next tick so that we don't prevent the bootup
                // stabilizing
                setTimeout(() => {
                  const $rootScope = $injector.get('$rootScope');
                  const subscription =
                      this.ngZone.onMicrotaskEmpty.subscribe(() => $rootScope.$digest());
                  $rootScope.$on('$destroy', () => { subscription.unsubscribe(); });
                }, 0);
              }
            ]);

    const upgradeModule = angular.module(UPGRADE_MODULE_NAME, [INIT_MODULE_NAME].concat(modules));

//.........這裏部分代碼省略.........
開發者ID:eromano,項目名稱:angular,代碼行數:101,代碼來源:upgrade_module.ts

示例4:

 next: () => {
   _log.add('onMicrotaskEmpty:started');
   _zone.run(() => _log.add('nested run'));
   _log.add('onMicrotaskEmpty:finished');
 }
開發者ID:DeepanParikh,項目名稱:angular,代碼行數:5,代碼來源:ng_zone_spec.ts

示例5: bootstrap

  /**
   * Bootstrap an AngularJS application from this NgModule
   * @param element the element on which to bootstrap the AngularJS application
   * @param [modules] the AngularJS modules to bootstrap for this application
   * @param [config] optional extra AngularJS bootstrap configuration
   */
  bootstrap(
      element: Element, modules: string[] = [], config?: any /*angular.IAngularBootstrapConfig*/) {
    const INIT_MODULE_NAME = UPGRADE_MODULE_NAME + '.init';

    // Create an ng1 module to bootstrap
    const initModule =
        angular
            .module(INIT_MODULE_NAME, [])

            .value(INJECTOR_KEY, this.injector)

            .config([
              $PROVIDE, $INJECTOR,
              ($provide: angular.IProvideService, $injector: angular.IInjectorService) => {
                if ($injector.has($$TESTABILITY)) {
                  $provide.decorator($$TESTABILITY, [
                    $DELEGATE,
                    (testabilityDelegate: angular.ITestabilityService) => {
                      const originalWhenStable: Function = testabilityDelegate.whenStable;
                      const injector = this.injector;
                      // Cannot use arrow function below because we need the context
                      const newWhenStable = function(callback: Function) {
                        originalWhenStable.call(testabilityDelegate, function() {
                          const ng2Testability: Testability = injector.get(Testability);
                          if (ng2Testability.isStable()) {
                            callback();
                          } else {
                            ng2Testability.whenStable(
                                newWhenStable.bind(testabilityDelegate, callback));
                          }
                        });
                      };

                      testabilityDelegate.whenStable = newWhenStable;
                      return testabilityDelegate;
                    }
                  ]);
                }
              }
            ])

            .run([
              $INJECTOR,
              ($injector: angular.IInjectorService) => {
                this.$injector = $injector;

                // Initialize the ng1 $injector provider
                setTempInjectorRef($injector);
                this.injector.get($INJECTOR);

                // Put the injector on the DOM, so that it can be "required"
                angular.element(element).data(controllerKey(INJECTOR_KEY), this.injector);

                // Wire up the ng1 rootScope to run a digest cycle whenever the zone settles
                // We need to do this in the next tick so that we don't prevent the bootup
                // stabilizing
                setTimeout(() => {
                  const $rootScope = $injector.get('$rootScope');
                  const subscription =
                      this.ngZone.onMicrotaskEmpty.subscribe(() => $rootScope.$digest());
                  $rootScope.$on('$destroy', () => { subscription.unsubscribe(); });
                }, 0);
              }
            ]);

    const upgradeModule = angular.module(UPGRADE_MODULE_NAME, [INIT_MODULE_NAME].concat(modules));

    // Make sure resumeBootstrap() only exists if the current bootstrap is deferred
    const windowAngular = (window as any /** TODO #???? */)['angular'];
    windowAngular.resumeBootstrap = undefined;

    // Bootstrap the AngularJS application inside our zone
    this.ngZone.run(() => { angular.bootstrap(element, [upgradeModule.name], config); });

    // Patch resumeBootstrap() to run inside the ngZone
    if (windowAngular.resumeBootstrap) {
      const originalResumeBootstrap: () => void = windowAngular.resumeBootstrap;
      const ngZone = this.ngZone;
      windowAngular.resumeBootstrap = function() {
        let args = arguments;
        windowAngular.resumeBootstrap = originalResumeBootstrap;
        ngZone.run(() => { windowAngular.resumeBootstrap.apply(this, args); });
      };
    }
  }
開發者ID:acramatte,項目名稱:angular,代碼行數:91,代碼來源:upgrade_module.ts

示例6:

 element['onPress'] = (...cbArgs: Array<any>) => {zone.run(() => deepCB.apply(target, cbArgs));}
開發者ID:donedgardo,項目名稱:react-native-renderer,代碼行數:1,代碼來源:wrapper_impl.ts

示例7: openCOE

 openCOE(path: string):void {
     this.zone.run(() => {
         this.path = path;
         this.page = "coe";
     });
 }
開發者ID:into-cps,項目名稱:intocps-ui,代碼行數:6,代碼來源:app.component.ts

示例8:

 this.interval = window.setInterval(() => {
   this.ngZone.run(() => {
     this.triggerPrometheusAlerts();
   });
 }, 5000);
開發者ID:IlsooByun,項目名稱:ceph,代碼行數:5,代碼來源:notifications.component.ts

示例9: openDSE

 openDSE(path: string):void {
     this.zone.run(() => {
         this.path = path;
         this.page = "dse";
     });
 }
開發者ID:into-cps,項目名稱:intocps-ui,代碼行數:6,代碼來源:app.component.ts


注:本文中的@angular/core.NgZone.run方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。