1

I'm in the process of incrementally upgrading an existing Angular 1 codebase to Angular 2 using ngUpgrade.

I'm converting an existing ng1 directive into an ng2 component. The old version has several $scope.$on handlers, listening for $scope.$broadcast or $scope.$emit messages. Is there an ng2 native way to listen for pub-sub events emitted from the existing codebase? Something with RxJS or Observables, I imagine, but I can't figure out what that might be.

UPDATE: I've managed to get this working for now, by pulling $scope into the ng2 injectable services:

import {upgradeAdapter} from './upgrade-adapter';
// ... 
upgradeAdapter.upgradeNg1Provider('$scope');

However, this seems very much less than ideal. Still hoping that someone out there will have thoughts on how to subscribe, from ng2, to messages broadcast from ng1.

Stuart Updegrave
  • 687
  • 5
  • 25

0 Answers0