当前位置: 首页>>代码示例>>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;未经允许,请勿转载。