2015-02-09 115 views
0

在尝试了this问题后,我再次询问如何使用AngularJS在Ionic框架中从Web检索数据。 基本上,我做了回答说:从网络离子阅读json文件

.factory('Advices', function($http) { 
    var advices = null; 
    $http.get('http://myurl.myext/myfile.json').success(function (data) { 
     advices = data; 
    }).error(function(error) { 
     console.log('error'); //even if there i print the error it prints nothing 
    }); 

    //etcetera 

我该如何拯救从我的服务器文件?

回答

1

请尝试以下代码

  var app = angular.module('myApp', ['ionic']); 
      app.controller('mainInfoFactory', ['$scope', '$http', function($scope,$http) { 
       $http.get("http://myurl.myext/myfile.json") 
       .success(function (response) 
       { 
       $scope.advices = response; 
       }) 
      .error(function(data) { 
       alert("ERROR"); 
       }); 
      }]); 

这里MYAPPmainInfoFactory分别AngularJS应用程序的名称和控制器。

例如:纳克应用内= “对myApp” NG控制器= “mainInfoFactory”