-1

m=5;
for(var i=0;i<m;i++){ 
   document.write(i); 
}

how output i in Angular

it is not working

$scope.B = [];
        angular.forEach([0, 1, 2, 3], function (value, index) {
            $scope.B.push(value);

        });

3

1 Answer 1

2

Your code is fine, the problem you have most be related to something else in your AngularJS application.. Check the console and add more info to the question.

In the loop are added the elements to the array $scope.B and showed in the view using json filter.

Code:

angular
  .module('App', [])
  .controller('DefaultController', ['$scope', function ($scope) {
    $scope.B = [];
    angular.forEach([0, 1, 2, 3], function (value, index) {
        $scope.B.push(value);
    });
  }]);
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.10/angular.min.js"></script>

<div ng-app="App">
  <div class="container" ng-controller="DefaultController">
    {{ B | json }}
  </div>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

Where's the explanation? Code only answers aren't very helpful

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.