Alvin Wee Alvin Wee - 5 months ago 10
AngularJS Question

No data when typing using bootstrap and angularJS

I am using typeahead to display all my cameraid and to search my data too but it does not giving me any data on the typeahead as it is showing me

[object Object]
.

Anybody can help me with this?

enter image description here

my html file:

<div class="container-fluid">

<h1><a href="http://localhost:8081/"><span class="glyphicon glyphicon-home
">Image Viewer</span></a></h1>
</div>
<br>
<div ng-controller="Hello" class="col-xs-12">


<b>Search:</b><br>

<input type="text" ng-model="searchBox" uib-typeahead="state for state in records | filter:$viewValue | limitTo:8" class="form-control">

<table class="table table-striped table-hover" style="width:55%">
<thead>
<tr>

<th>CamID</th>
<th>Timestamp</th>
<th>View Image</th>

</tr>
</thead>

<tbody>
<tr ng-repeat="record in records | filter:searchBox | orderBy:'+timestamp'">

<td>{{record.cameraid}}</td>
<td>{{record.timestamp}}</td>
<td>{{record.filename}}</td>
<td><button class="btn btn-primary" ng-click="toggleCustom()" onclick="myFunction()">View</button></td>

</tr>
</tbody>
</table>


My jsp file:

var camListApp = angular.module('camListApp', ['ui.bootstrap'])
camListApp.controller("Hello", ["$scope", "$http", function($scope, $http){

$scope.custom = true;
$scope.toggleCustom = function() {
$scope.custom = ! $scope.custom;
};

$http.get('http://localhost:8081/camera/list').then(function(response) {
console.log(response);
$scope.records= response.data;
});
}]);


My json data:

[{"id":23,"cameraid":"001","timestamp":"2016/06/15 17:27","filename":"452c5d867b563e937d44d48ebc326c7a"},
{"id":24,"cameraid":"000000006f4280af","timestamp":"2016/06/15 17:27","filename":"ee90428e4e0c19ba9858285398bf4fbb"},
{"id":25,"cameraid":"002","timestamp":"2016/06/15 17:28","filename":"c9a4fb339f6981ffd679937724167de8"},
{"id":26,"cameraid":"000000006f4280af","timestamp":"2016/06/15 17:28","filename":"a1df86417d958e670750cf8172a2b7dd"}

Answer

Actually you are returning all the objects that's why you get "object Object", you need to specify which part you gonna use.

uib-typeahead="state.cameraid as state.cameraid for state in records | filter:$viewValue | limitTo:8"

The first state.cameraid is what you display in the list the second is the value.