I believe this is a pretty simple question and I have found some solutions here on forum but it looks that I did everything right but still getting only last value. I've wrote this simple example. Somebody could explain me, where is my mistake?
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope, $http) {
$scope.name = 'Reinforcement';
$http.get('test.json')
.success(function (data) {
$scope.test = data;
});
$scope.getName = function () {
for (var i = 0; i < $scope.test.length; i++) {
$scope.parent = $scope.test[i].name
}
}
});
html
<div class="dropdown category" style="position:relative">
<a href="#" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> Category <span class="caret"></span></a>
<ul class="dropdown-menu">
<li ng-repeat="objName in test" ng-click="getName()">
<a href=""> {{objName.name}}</a>
</li>
</ul>
</div>
{{ parent }}