angular / ngMigration-Forum

109 stars 7 forks source link

Fix documentation on upgrading components #5

Open jpzwarte opened 6 years ago

jpzwarte commented 6 years ago

The official upgrade docs at angular.io mention that in order to use UpgradeComponent (to upgrade an angular.js component for use in angular) the root component of your app has to be an angular.js component. For us this wasn't an option. After googling i found a solution to this problem on SO:

  providers: [
    {
      provide: '$scope',
      useFactory: i => i.get('$rootScope'),
      deps: ['$injector']
    }
  ]

In the ngModule that contains the UpgradeComponent directive, provide the $scope as shown above. This will fix the $scope missing error and get the angular.js component to work.

ellamaolson commented 6 years ago

@jpzwarte Thank you for posting this solution here.