What is the difference between ‘this’ vs $scope in angularjs controllers?



What is the difference between ‘this’ vs $scope in angularjs controllers?..

Answer / Sangeet Kumar Yadav

'this' refers to the window object by default in JavaScript, but in AngularJS controllers, it refers to the controller itself. To access properties and methods on the scope, use `$scope`. If you want to refer to the same object as both 'this' and $scope, you can use `function MyController($scope) { this.$scope = $scope; }`.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More AngularJS Interview Questions

What is service heroservice?

1 Answers  


What is json web token in angularjs?

1 Answers  


What did you like about working with angular 2?

1 Answers  


How AngularJS compilation is different from other JavaScript frameworks?

1 Answers  


What's new in angular 8?

1 Answers  


Explain what is the difference between link and compile in angular.js?

1 Answers  


What are animating elements in angularjs?

1 Answers  


What is the purpose of transclusion?

1 Answers  


What are services in javascript?

1 Answers  


How to validate email in angular 4 using formgroup or custom regexp?

1 Answers  


What are the components in angular2?

1 Answers  


What is the main purpose of find index in angularjs, and what does it return if no value is found?

1 Answers  


Categories