0

I cannot understand "this" in AngularJS. I found it on function which was associated with ng-click.

html

<button ng-click="func()"></button>

javascript:

function func(){
    console.log(this);
}

I want to use "this" through another function. So I want to know how to access "this" on another function. Please teach me.

pandanoir
  • 53
  • 1
  • 5
  • this is not specific to angularjs it's vanilla javascript. Maybe relevant : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind – luxcem Feb 07 '14 at 13:52
  • 4
    This question appears to be off-topic because you can easily find out for yourself what this is. The question lacks presentation of a minimal understanding of what `this` means in JavaScript. – Golo Roden Feb 07 '14 at 13:53

1 Answers1

0

I understand the comments saying that you could have found that by yourself but we all started from scratch one day... so:

To use this in another function:

function func(){
  anotherFunc(this);
}

function anotherFunc(oldThis){
// do something...
}

You should also read about the famous: var self = this;

var self = this?

What underlies this JavaScript idiom: var self = this?

Community
  • 1
  • 1
glepretre
  • 8,365
  • 5
  • 41
  • 56
  • I'm sorry for leaving without saying I solved this problem by myself. I'm able to do thing I want to do. Thank you for answering. – pandanoir Mar 02 '14 at 07:55