angularjs - Output doesn't come for REST API Angular -


i working on tutorial build angularjs app fetching information of users. when running app , output doesn't display.

my index.html

    <!doctype html> <html data-ng-app="mycontactapp" >     <head>             <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/y6pd6fv/vv2hjna6t+vslu6fwyxjcftcephbnj0lyafsxtsjbbfadjzaleqsn6m" crossorigin="anonymous">             <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rhyon1irsvxv4nd0jutlngaslcjuc7uwjduw9svrlvryoopp2bwygmgjqixwl/sp" crossorigin="anonymous">             <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular.min.js"></script>             <script src="app.js"></script>             <script src="appconfig.service.js"></script>             <script src="appname.service.js"></script>             <script src="contact.controller.js"></script>             <script src="contactdata.service.js"></script>              <title>my contact application</title>     </head>      <body>            <main>         <div class='container' ng-controller="contactcontroller ctrl">             <div class='row'>                 <ul class="list-group">                         <li class="list-group-item" ng-repeat="con in ctrl.contactarr" data-ng-click="ctrl.selectuser($index)">                             <span>{{con.name.first+ " "+con.name.last}}</span>                         </li>                 </ul>             </div>             <div class='row'>                 <div class="media">                     <div class="media-left">                          <a href="#">                             <img data-ng-src="{{ctrl.selecteduser.picture.medium}}">                         </a>                          </div>                         <div class="media-body">                             <h4 class="media-heading">{{ctrl.selecteduser.name.first+ " "+ctrl.selecteduser.name.last}}</h4>                         <div>                             <p>                                 <h6>location</h6>                             </p>                             <p>                                 {{ctrl.selecteduser.location.street+" "+ctrl.selecteduser.location.city+" "+ctrl.selecteduser.location.state+" "+ctrl.selecteduser.location.postcode}}                         </div>                         <div>                             <p>                                  <h6>phone</h6>                                 </p>                             <p>{{ctrl.selecteduser.phone}}</p>                          </div>                         <div>                             <p>                                 <h6>email</h6>                             </p>                             <p>                                 {{ctrl.selecteduser.email}}</p>                            </div>                     </div>             </div>         </div>     </main>      </body>  </html> 

my app.js

 var app=angular.module("mycontactapp",[]); 

my appconfig.service.js

    (function(){  var app=angular.module("mycontactapp");  app.service("appdataservicesvc",function(appnamesvc){     this.name=appnamesvc;     this.author='bhaskar';     this.builddate=new date().todatestring();  }); })(); 

my appname.service.js file :-

   (function (){ var app=angular.module("mycontactapp"); app.value("appnamesvc","my new contact list"); })(); 

my contact.controller.js file

(function(){      var app=angular.module("mycontactapp");      app.controller("contactcontroller",contactctrl);      function contactctrl(contactdatasvc){     var self=this;     contactdatasvc.getcontacts().then(function(data){        self.contacts=data;    })                        this.selectuser=function(index){                         this.selecteduser = this.contactarr[index];                     }  } })(); 

my contactdata.service.js

(function(){      var app=angular.module("mycontactapp");      app.service("contactdatasvc",function($http){         var self=this;         self.getcontacts=function(){         var response1=$http.get('http://localhost:3000/contacts');         var response2=response1.then(function(response){             return response.data;         });         return response2;     }     });     })(); 

i have created db.json running on json-server , using rest api. should display contact details doesn't display on browser. unable figure out have made mistake.

in controller use: self.contacts=data;

change ng-repeat="con in ctrl.contactarr" to:

ng-repeat="con in ctrl.contacts" 

also pass con selectuser : data-ng-click="ctrl.selectuser(con)"

demo plunker


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -