I am looking at a component of Angular UI Tree . The specific code I am looking at is:
<a class="pull-right btn btn-primary btn-xs" data-nodrag ng-click="newSubItem(this)" style="margin-right: 8px;">
The line all makes perfect sense to me, except for the use of this
for the ng-click. I am familiar with the use of this
in Javascript and how it differs from the use of self
in classical OO. But I am wondering what exactly is being referred to when passed to this function call?
The code is contained in this basic example .
Well, In here this
refers to the scope and it will include every variable, functions which inside of it.
Wherever we use this, it will always return scope.
Here, I am passing this from parent and child, but both shows same output as $SCOPE
<body ng-controller="AppController">
<div><a ng-click="aClick(this)">Click a</a>
<div>
<a ng-click="bClick(this)">Click b</a>
</div>
</div>
{{aValue}} {{bValue}}
</body>
Please find the working plunker: http://plnkr.co/edit/IdXB1ZtXMpFS3soxcBIz?p=preview
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.