I am using AngularJS to build a web application. I have a server running PHP which fetches some data from the SQL-database and encodes it to JSON. On the client side I make use of the Angular $http service to fetch it, parse it and it succeeds, however I am not able to use the variable assigned with the fetched data. This is the code to perform the HTTP request:
factory.employees = factory.getEmployeesFromServer();
factory.getEmployeesFromServer = function() {
return $http.get("http://localhost/scrumboard/get_user.php")
.success(function(response) {
for(var property in response) {
console.log("PROP: "+property);
if (response.hasOwnProperty(property)) {
console.log("Has ownProperty: " + property)
}
}
console.log(JSON.stringify(response));
return response.data;
})
.error(function(response, status, headers, config) {
})
}
The print of the properties just contains zeroes and ones. However when the Stringify-print reaches the console it looks like this:
[{"email_id":"rob_en@gmail.com","user_name":"rob","first_name":"Robert","last_name":"Allen","password":"roballen","admin_right_id":"2"},{"email_id":"rob_ena@gmail.com","user_name":"robad","first_name":"Roben","last_name":"Lena","password":"aleno","admin_right_id":"1"}]
You can see that it is an array out of two objects, but I cannot access these properties of the objects, even though I can use it with an ng-repeat
. See the following snippet:
<li ng-repeat="emp in availableEmployees">
<label class="btn btn-primary" ng-model="checkModel" btn-checkbox>
HELLO {{emp.user_name}}
</label>
</li>
That code produces two list items but no text.
The following image is from the debug console, inspecting employees
object:
I am quite new to web development and hope someone could help me out! I have done a lot more debugging but dont want to bloat this post no more, so just ask if you need any specific info.