Philson cedric
Philson cedric

Reputation: 13

'This' conflicts in angular and Jquery

I am trying to migrate a angularjs application into angular. The old application had jquery functionalites. I tried using the same. Issue with 'this' element.

When loading in angular, angular takes 'this' element has its component one and jquery 'this' element doesnt show up.

enter image description here

Appreciate any help!!!

Upvotes: 0

Views: 214

Answers (1)

adz5A
adz5A

Reputation: 2032

Just replace your arrow function in click by function.

using this inside arrow functions body will not create a new lexical context , hence your result.

Inside jQuery methods, such as click you need to use functions expressions that will allow the lexical context this to be bound to the current dom element.

Important reading about this, http://perfectionkills.com/know-thy-reference, spec about arrow functions and their pitfalls can be useful too.

Upvotes: 1

Related Questions