No provider for $scope! exception with UpgradeAdapter (upgrading angular1 directive to angular2)

1,527 views
Skip to first unread message

Abhi

unread,
Jan 14, 2016, 1:31:34 AM1/14/16
to AngularJS

I am using UpgradeAdapter to use an angular1 directive in my angular2 app. I followed the steps mentioned on angular2 upgrade guide

See this plunk for code. It is resulting me into this error -

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

I have an angular1 directive which is element type, with controllerAs style. Also I am not using $scope in the controller code. I am trying to use this angular1 directive within my angular2 app.

So I instantiate the UpgradeAdapter and call upgradeNg1Component method on it with argument as name of my angular1 directive and I pass it in the directive input for my angular2 component.

But then it results in the above error.

Any clue what I may be missing?

Swapnil Sawant

unread,
Jan 14, 2016, 6:09:44 PM1/14/16
to AngularJS
I am also stuck on this same error! 

Daniel Smith

unread,
Jan 19, 2016, 2:21:37 PM1/19/16
to AngularJS
I could also use some direction on this problem.

Eric Martinez

unread,
Jan 19, 2016, 3:29:32 PM1/19/16
to AngularJS

Daniel Smith

unread,
Jan 19, 2016, 7:13:54 PM1/19/16
to ang...@googlegroups.com
That answer doesn't really help.  The poster comments that he is still receiving the error.

I have come to notice that the error only seems to occur if you reference the Angular2 version of a downgraded Component whose template includes an upgraded AngularJS directive.

On Tue, Jan 19, 2016 at 3:29 PM, Eric Martinez <eric.ma...@gmail.com> wrote:

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/dqefRUKpfQs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Abhi

unread,
Jan 20, 2016, 1:35:21 AM1/20/16
to AngularJS
In my case, I am only referencing an upgraded NG1 component in the template of an NG2 component. This is with Angular2 beta library. 

Vincent Audy

unread,
May 19, 2016, 3:01:19 PM5/19/16
to AngularJS
I have the same issue, anyone have idea?

Manish Pal

unread,
May 23, 2016, 10:22:42 PM5/23/16
to AngularJS
Here's your code in working form https://plnkr.co/edit/VzuopVilmDK5sQaQcoDh?p=preview

Couple of things:
1. you need to downgrade the ng2 component as well, because a hybrid ng1 + ng2 app would start as an ng1 app only.
2. your ng2 component was using templateUrl instead of template, even though it was giving an inline template.

Abhi

unread,
May 24, 2016, 1:57:54 AM5/24/16
to AngularJS
Hey Manish, Thanks for your  solution.
Downgrading angular2 component to use with angular1 App is one such usage. But what if I have to do the other way i.e consume angular1 directive into an angular2 App. 
That's what my use case is. I have a newly written angular2 App where I want to use existing angular1 directive along with other angular2 components. Are you saying that is not supported?

About #2, I admit that's a typo. Even with template field, it doesn't work. 

By the way, this was some months back with beta.1, I have not checked if the problem still exist with rc builds.

Manish Pal

unread,
May 24, 2016, 4:57:59 AM5/24/16
to AngularJS
Yes looks like that.

There are two key things to understand about what happens in the DOM of a hybrid application:

  1. Every element in the DOM is owned by exactly one of the two frameworks. The other framework ignores it. If an element is owned by Angular 1, Angular 2 treats it as if it didn't exist, and vice versa.
  2. The root of the application is always an Angular 1 template.
Reply all
Reply to author
Forward
0 new messages