2017-07-11 57 views
-3

Service Code离子应用

调用从服务器的数据在我的应用程序离子我能够从.factory为我的数据,但我想从服务器(JSON)得到我的数据,我已经尝试了很多代码已经但未能解决问题。请建议我在services.js文件中写一个代码,以便我可以从http://localhost:3000/statments获取我的数据。

看一看上面的维修代码,看看我从services.js获取我的数据

回答

0
//controller 
app.controller('YourControllerName', YourControllerName); 
function YourControllerName($scope, myService) { 
    $scope.fetchData = function() { 
     myService.getData().then(function(result) { 
     console.log(result.data); 
     }); 
    } 
}; 

//service.js 
app.service("myService", function ($http) { 
    this.getData = function() { 
     return $http.get('http://localhost:3000/'); 
    } 
});