【问题标题】:Calling data from server in ionic app在离子应用程序中从服务器调用数据
【发布时间】:2017-07-11 10:20:26
【问题描述】:

在我的 Ionic 应用程序中,我可以从 .factory 提供我的数据,但我想从服务器 (JSON) 获取我的数据,我已经尝试了很多代码,但无法解决问题。请建议我在 services.js 文件中编写代码,以便我可以从 http://localhost:3000/statments 获取数据。

看看上面的服务代码,看看我是如何从 services.js 中获取数据的

【问题讨论】:

    标签: angularjs json ionic-framework


    【解决方案1】:
    //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/');
         }
     });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      • 1970-01-01
      • 2017-05-30
      • 1970-01-01
      • 1970-01-01
      • 2016-11-19
      • 1970-01-01
      相关资源
      最近更新 更多