My goal is to populate a table with JSON data using ng-repeat by clicking a button. I need to input either a first name or last name in order to display the results in the table. Is this the correct JavaScript function for achieving this?
JavaScript Function:
$scope.clickButton = function(enteredValue) {
$scope.reset();
$scope.items = data;
angular.forEach($scope.items, function (item) {
if(item.fname === enteredValue || item.lname === enteredValue ){
$scope.results.push({
first: item.fname,
last: item.lname,
address: item.address,
phone: item.phone
});
JSP:
<input id="fName" name="fName" type="text" data-ng-model="enteredValue.firstName" />
<input id="lName" name="lName" type="text" data-ng-model="enteredValue.lastName" />
<button class="btn btn-primary" data-ng-click='clickButton(enteredValue)'>Button</button>
For a live example, check out Plnkr.