Showing posts with label angularjs $scope vs var. Show all posts
Showing posts with label angularjs $scope vs var. Show all posts

angularjs $scope vs var

Question is when to use $scope vs var and vice versa?

Ans: Answer is very simple and must be followed.

When You want two way binding or your variable is used in the UI part use $scope otherwise var.

For example:


var a = 10;

$scope.b = x * 5;

{{x}} - undefined

{{y}} - 50


So the conclusion is if your variable not interact to view part then it must be declared as var.