javascript - ionic retrive data from database with http request -


i'm tring learn how use ionic framework,

i've made controller data database using play 2.0 web server. factory code :

    .factory('projects', function($http) {     var projects =  [];     return {         getprojects: function() {                $http.defaults.headers.post['content-type'] = 'application/json';                    return $http({                             method: 'post',                              url: 'http://localhost:8101/getprojects',                              datatype: 'json',                             headers: { 'content-type': undefined }              }).success(function(data, status) {                  projects= data;                 return projects              }).error(function(arg) {             alert("error ");         });         }     } }) 

and controller :

.controller('rootsctrl', function($scope, projects, $http) {      $scope.projects= projects.getprojects();   }) 

and here view :

<ion-view view-title="projects">   <ion-content>     <ion-list>       <ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="project in projects" type="item-text-wrap" >         <h2>{{project.try}}</h2>                 </ion-item>     </ion-list>   </ion-content> </ion-view> 

the web server return fake data now.

i can't understand why, in view, value project.try isn't show, row present. if have 2 values, in html can see 2 row, without "name". thanks

factories singletons , return object contains members of service.

.factory('project', function($http, $log) {   return {     getprojects: getprojects   };    function getproject(){     var config = {       method: 'post',        url: 'http://localhost:8101/getprojects',        headers: { 'content-type': undefined }     }     return $http(config).then(success).catch(failure);   }    function success(resp){     return resp.data;   }    function failure(error){     return error;   } }); 

$http returns promise.

//controller  .controller('rootscontroller', function(project){   var vm = this;    fetchproject();    function fetchproject(){     project.getproject().then(success, failure);   }    function success(data){     vm.projects = data;   }    function failure(err){     // error handling   } }); 

in view:

<ion-item ng-repeat = "project in vm.projects">   {{project}} </ion-item> 

also in states:

controller: 'rootscontroller vm' because ionic has issues controlleras syntax. 

also not posting data? , can see rows , not names because project object exists might not contain key called try


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -