1

I built web service with php that reads a database and echo json. I go to the path to see the result and the result is success. Here an example of my web service.

[{"id":"1","skill":"1","src":"walmart","total":"1"},{"id":"1","skill":"1","src":"target","total":"2"}]

Here is my app.js code

(function () {
'use strict';
var app =   angular.module('myApp', ['angular.filter']);
// Declare app level module which depends on views, and components
app.controller('DeveloperTable', function ($scope, $http) {
        var vm = this;

        // GET request example:
        $http({
            method: 'GET',
            url: '../_includes/web_service_person.php'
        }).then(function successCallback(data) {
            vm.developer = data;
        }, function errorCallback(data) {
            console.log(":(");
        });
    });

})();

Here is my index.html

<div ng-controller="DeveloperTable">
    <h4>Developer Assesment</h4>
    <table class="table">
        <tr>
          <th>pid</th>
          <th ng-repeat="(skill, value) in developer | groupBy: 'skill'">
            {{skill}}
          </th>
        </tr>

The funny part is that I don't have errors in my console, but I'm not getting data either. What I'm missing here?

Edit: The groupBy filter comes from the angular-filter library

2
  • what output are you trying to achieve here? Commented Sep 1, 2016 at 16:45
  • 1
    ng-controller="DeveloperTable as vm" and then iterate vm.developer Commented Sep 1, 2016 at 17:06

2 Answers 2

1

The ng-repeat syntax is: ng-repeat="(key, value) in myObj". Based on the json you posted, vm.developer is an array, so skill would be set as the array index.

I am also not so sure about that groupBy: 'did', because I don't see any did property in your json objects.

Try it like:

<th ng-repeat="data in vm.developer | groupBy: 'id'">
    {{data.skill}}
</th>
Sign up to request clarification or add additional context in comments.

3 Comments

I'm using this dependency therefore the syntax si slightly different.
GroupBy: 'did' was a typo. I update my question. Thank you for letting me know.
haha, well dependencies like that should definitely be mentioned in the original question.
1

Couple of things:

You need to do $scope.developer = ... in your code, vm.developer is not in your scope on the page.

That aside, you can:

Open Firebug in your browser, go to the network tab and look at the HTTP request to your web service. You can see if it returns data. If it does, debug it like:

Look at your HTML, and add <pre>{{developer | json}}</pre> and I think you'll see that it's empty.

3 Comments

Either $scope.developer = ...; to not expose entire controller on scope. OR ng-controller="DeveloperTable as vm" to expose controller on scope as vm
I did both, <pre>{{developer | json}}</pre> and opened the dev tools, network, response and my json object is there.
so the <pre>{{developer | json}}</pre> is rendering your object now? how about <pre>{{developer | groupBy: 'skill' | json}}</pre> ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.