Display Json Data in View using AngularJS and PHP

1. For this example I am using php server side code to gather the data from the data base and return it as a Json format. For this we can use the buid in code for php i.e.
json_encode($data);

for eg: (using Codeigniter model)

                $check_sql = "Select * from user where about_status = 1"; //status is flag for the active user
$check = $ci->db->query($check_sql);
$row = $check->result();

echo json_encode($row);

which gives output as:

{
"records": [
  {
    "Name" : "Yubraj Pokharel",
    "City" : "Kathmandu",
    "Country" : "NP"
  },
  {
    "Name" : "Chitra Shrestha",
    "City" : "Pokhara",
    "Country" : "NP"
  },
  {
    "Name" : "Prayag Upd",
    "City" : "California",
    "Country" : "US"
  },
  {
    "Name" : "Sudhan Pokharel",
    "City" : "Nepalgunj",
    "Country" : "NP"
  },
  {
    "Name" : "Mr Tom Cruise",
    "City" : "California",
    "Country" : "US"
  }
]
}

2. calling it from the angular page:

<html>
<head>
<title>Json Data</title>
        call angular js here
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-12" ng-app="myApp" ng-controller="customersCtrl"> 
<table class="table">
<tr>
<th>Name</th>
<th>country</th>
</tr>
<tr  ng-repeat="x in names">
     <td>{{ x.Name }} </td>
     <td>{{ x.Country }}</td>
   </tr>
</table>
</div>
</div>
</div>

<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
    $http.get("http://localhost/angular/news.php")
    .success(function(response) {$scope.names = response.records;});
});
</script>
</body>
</html>

3. Here it is done enjoy happy coding :)

22 comments:

  1. Pleasant Post. It is truly intriguing to peruse from the earliest starting point and I might want to share your site to my circles, continue sharing more like this.
    Angularjs courses in Chennai | Angularjs Training in Chennai

    ReplyDelete
  2. This technical post helps me to improve my skills set, thanks for this wonder article I expect your upcoming blog, so keep sharing...
    PHP Training Institute in Chennai|Best PHP training in chennai

    ReplyDelete
  3. Hi admin, i went through article. As we all know, .net is most popular programming language and it offer huge career prospects for talented professionals. It’s totally awesome, keep on updating your blog with such awesome information. .Net Training in Chennai

    ReplyDelete
  4. Excellent post! Thank you for Sharing. We are the best erp software providers in chennai. For more details call +91 9677025199 or email us on info@bravetechnologies.in
    erp in chennai

    ReplyDelete
  5. Excellent post! I heve read your blog it's very interesting and informative. Keep sharing.
    erp providers in chennai | erp software chennai

    ReplyDelete
  6. Your post is useful for me. Thanks for sharing this technical information with us. Great effort.
    PHP training classes | PHP training institute in chennai

    ReplyDelete
  7. Thanks for sharing such informative article. Know about Know about English to Tamil from techfizy.

    ReplyDelete
  8. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry. JavaScript Training in Chennai

    ReplyDelete
  9. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.

    java training in bangalore

    ReplyDelete
  10. Your new valuable key points imply much a person like me and extremely more to my office workers. With thanks; from every one of us.


    white label website builder

    mobile website builder

    ReplyDelete
  11. Good one.I appreciate you for sharing this knowledge.Thank you so much for the examples.Its very helpful for me and newbies.I learned much .Have a look on yii2 development company,

    ReplyDelete
  12. Appreciation for really being thoughtful and also for deciding on certain marvelous guides most people really want to be aware of.

    AWS Training in Chennai

    ReplyDelete
  13. Your good knowledge and kindness in playing with all the pieces were
    very useful. I don’t know what I would have done if I had not
    encountered such a step like this.

    digital marketing training in chennai

    seo training in chennai

    ReplyDelete
  14. Thank you so much for such valuable information sharing. It’s highly appreciated.

    Microsoft Azure Admin Training in Chennai
    Microsoft Azure Admin Training

    ReplyDelete
  15. Wonderful post!!Thank you for sharing this info with us.
    Keep updating I would like to know more updates on this topic
    Very useful content, I would like to suggest this blog to my friends.

    PHP Course Chennai

    PHP Training Chennai

    ReplyDelete
  16. Nice Post I learned a lot From the Post Thanks for sharing, learn the most ON-DEMAND software Training in Best Training Institutions
    Instructor-LED Salesforce Online Training

    Professional Salesforce CRM Training
    Salesforce Training online in India

    ReplyDelete
  17. wow great Article, the details you have provided are much clear, easy to understand, if you post some more Article, it will be very much useful for me.
    PHP Training in Chennai

    ReplyDelete
  18. The blog you presented was very nice and interesting which helped me to get update on the recent technologies.

    angularjs training in chennai

    devops training in chennai

    ReplyDelete
  19. Thanks for sharing the valuable post. Kanhasoft is the well known Custom PHP Web Developer in India. We providing outsourcing services to USA, UK, Europe, Canada, Germany, UAE, Dubai, Australia, France, Brazil, Turkey, Singapore, Japan, Saudi Arabia, Ukraine, Spain, Belgium, Netherlands, Luxembourg, New Zealand, Argentina, South Africa, Greece, Denmark, Poland, Switzerland and more. Visit our site to know more.

    ReplyDelete
  20. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area. We are providing AngularJS training in Velachery.

    For more details: AngularJs training in velachery

    ReplyDelete