Angular services can be downgraded and injected into AngularJS. In normal operation, Angular services would be bootstrapped with the application, but because of ng-upgrade being a hybrid mode, this is not the case. The upgrade adapter comes with an addProvider method that must be used in the interim.
Since Angular is bootstrapped with the upgrade adapter, there is no place to register Angular services. Fortunately the upgrade adapter's addProvider method can do this:
upgradeAdapter.addProvider(Phones);
Lastly, AngularJS must be informed about the Angular service:
// The service to downgradeimport { A2DowngradeService } from"./services/a2-downgrade";// AngularJS Vendor Importimport*as angular from"angular";// Import the upgradeAdapter singletonimport { upgradeAdapter } from"./upgrade-adapter";// Name the applicationconstAPPNAME="angular-upgrade-example";// Register classic AngularJS modulesangular.module(APPNAME).factory("a2DowngradeService",upgradeAdapter.downgradeNg2Provider(A2DowngradeService) );
Using this downgraded service in an AngularJS directive is as simple as: