Kevin Kai Kevin Kai - 2 years ago 69
AngularJS Question

Consume Rest web service with AngularJS

This is my json data from my web service

[{"cameraid":"ggh","timestamp":"2016/05/10 01:31","filename":"ffffpg"},
{"cameraid":"mason","timestamp":"2016/05/10 05:31","filename":"aaa.png"}

My html file

<!doctype html>
<html ng-app="camListApp">
<title>hi AngularJS</title>
<script src=""></script>
var camListApp = angular.module('camListApp');
camListApp.controller('Hello', ['$scope', '$http', function($scope, $http){
function Hello($scope, $http) {
success(function(data) {
$scope.record= data;
<div ng-controller="Hello">
<table border = 1>

<tr ng-repeat="record in record">

no data on table

When I run my browser, no data is show in the table. What have I miss out or done wrong? Anybody can help? As i want to display all the data in the table

Answer Source

There are below issues in your code, which once fixed will make yor code working:

  1. Missing [] from module definition. Change it as below:

    var camListApp = angular.module('camListApp', []);
  2. The controller definition is incorrect as you have 2 callback functions (One within other). You only need one:

    camListApp.controller('Hello', ['$scope', '$http', function($scope, $http){
        success(function(data) {
            $scope.record= data;

Also the preferred way of handlin promises is using .then instead of .success

  1. When you use the $http service it wraps up your data in an object and actual data is an attribute exposed on the returned response in callback. Access the data attribute in response as below:

    $http.get('').then(function(response) {

I have created a working bin with sample data from my github repos:,js,console,output

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download