Working on developing a web application using AngularJS has led me to encounter an issue. I have a PHP server that retrieves data from an SQL database and encodes it into JSON. Utilizing the Angular $http service on the client side, I am able to successfully fetch and parse the data. However, I am facing difficulty in utilizing the variable assigned with the fetched data.
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 only shows zeros and ones, but when the Stringify-print prints to the console, it displays the data correctly as an array with two objects:
[{"email_id":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94e6fbf6cbf1fad4f3f9f5fdf8baf7fbf9">[email protected]</a>","user_name":"rob","first_name":"Robert","last_name":"Allen","password":"roballen","admin_right_id":"2"},{"email_id":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2e5c414c714b404f6e49434f4742004d4143">[email protected]</a>","user_name":"robad","first_name":"Roben","last_name":"Lena","password":"aleno","admin_right_id":"1"}]
Although I can use ng-repeat
to loop through the data with the code snippet below, it does not display any text:
<li ng-repeat="emp in availableEmployees">
<label class="btn btn-primary" ng-model="checkModel" btn-checkbox>
HELLO {{emp.user_name}}
</label>
</li>
Debugging further, I inspected the employees
object as shown in the image below:
Seeking assistance as a relative newcomer to web development and willing to provide more details upon request!