Xameer
Xameer

Reputation: 31237

Unable to initialize and fetch array from controller in AngularJS

I was trying to initialize and fetch the array values from the controller.

The fiddle is here.

var app = angular.module('carApp', []);

app.controller('carAppCtrlr', function ($scope) {
    $scope.vehicles = [{
        type: 'car',
        color: 'red'
    }, {
        type: 'bike',
        color: 'black'
    }];
};);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div data-ng-app='carApp' data-ng-controller='carAppCtrlr'>
    <ul>
        <li data-ng-repeat='v in vehicles'>{{v.type +" " + v.color}}</li>
    </ul>
</div>

Output

The values are not getting printed:

output

Upvotes: 1

Views: 346

Answers (1)

Ashot
Ashot

Reputation: 1300

delete semicolon in last line of your controller definition

var app = angular.module('carApp', []);

app.controller('carAppCtrlr', function ($scope) {
   $scope.vehicles = [{
    type: 'car',
    color: 'red'
    }, {
    type: 'bike',
    color: 'black'
   }];
});

Upvotes: 3

Related Questions