Skip to content

NgUpgrade bootstrap not resolving Ng1 rootScopePrototype when ng1 bootstrap is deferred #6547

@danoph

Description

@danoph

While trying to upgrade an app, I ran into an issue with protractor where ngUpgrade's bootstrap is not waiting for ng1 to completely load if deferred bootstrapping is used (which is what protractor and browser plugins like Batarang do). I am getting this error when running protractor:
Failed: Error while waiting for Protractor to sync with the page: "[ng:test] no injector found for element argument to getTestability\nhttp://errors.angularjs.org/1.4.8/ng/test"

After some digging in UpgradeAdapter, I noticed there is an IF check around the ng2 bootstrap that doesn't run ng'1 rootScope.$apply function. If ng1 bootstrap is deferred, the rootScopePrototype doesn't get resolved before this runs:

Promise.all([this.compileNg2Components(compiler, hostViewFactoryRefMap), ng1compilePromise])
    .then(() => {
      ngZone.run(() => {
        if (rootScopePrototype) {
          rootScopePrototype.$apply = original$applyFn;  // restore original $apply
          while (delayApplyExps.length) {
            rootScope.$apply(delayApplyExps.shift());
          }
          (<any>upgrade)._bootstrapDone(applicationRef, ng1Injector);
          rootScopePrototype = null;
        }
      });
    }, onError);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions