EXCEPTION: There is no provider for $ scope! (function (scope, elementRef) {-> $ scope)

I am using ngUpgrade to use the angular1 directive in my angular2 application. I followed the steps mentioned in angular2 update guide

See plunk for code. This leads me to this error -

EXCEPTION: No provider for $scope! (function (scope, elementRef) { -> $scope) 

Can I understand what I am missing?

+5
source share
1 answer

In addition to adding -

 angular .module('interestApp') .directive('appRoot',upgradeAdapter.downgradeNg2Component(AppComponent)); 

because (quoting documents ) -

An application root is always an Angular 1 template.

This is why Angular 1 needs to know about Angular 2 AppComponent.

I found that removing the next line from main.ts helps clear the No provider for $scope! error No provider for $scope! -

platformBrowserDynamic().bootstrapModule(AppModule);

Since you do not need two boot processes in a hybrid application.

0
source

Source: https://habr.com/ru/post/1240522/


All Articles