Gaurav Aggarwal Gaurav Aggarwal - 8 months ago 39
AngularJS Question

How X is getting value in angularJS

I am new to angular.js just working on a function

. in which i am using
ng-repeat="x in name"
where i have defines some values in
but i didn't defines x anywhere in complete code.

Here is my code:

<div ng-app="myApp" ng-controller="namesCtrl">

<li ng-repeat="x in names">
{{ + ', ' + }}


angular.module('myApp', []).controller('namesCtrl', function($scope) {
$scope.names = [

Everything is working fine but i wonder how the values are coming in
or what exactly
is doing here as i am just calling
but not defining any value in


x is being defined by angular's ng-repeat directive. It is iterating over all the values in names and binding each value to x in turn.

Note that you can choose any other valid variable name instead of x.

The reason there is no conflict between each value of x is that each iteration gets its own $scope.

See also the ng-repeat documentation.