I'm new to angular js,I have 2 goals:
- OnClick, display a single person's name from a JSON array,
- Randomize name on every click
I'm stuck at the part where i need to pass the json data to the view: when i click the button i get [object object], [object object], [object object] Could someone please assist?
[
{"name": "John"},
{"name": "Sue"},
{"name": "Sally"},
{"name": "Jim"},
{"name": "Bev"},
{"name": "Joe"},
{"name": "Jess"}
]
script
var peopleApp = angular.module('peopleApp', []);
idApp.controller('peopleCtrl', ['$scope', '$http', function ($scope, $http){
$scope.randomPerson = function(){
$http.get('js/people.json').
success(function(data) {
$scope.person = data;
console.log(data);
});
}
}]);
view
<div class="content">
<div ng-controller="peopleCtrl">
<p ng-bind="name"></p>
<button ng-click="randomPerson()">
Show random person's name
</button>
<p ng-bind="person"></p>
</div>
</div>