2015-11-22 83 views
1

我使用AngularJS處理PhoneGap我需要一些幫助來從遠程JSON服務器獲取數據。我怎麼能在模塊工廠做到這一點?AngularJS module.factory獲取遠程JSON

我的JSON文件:

[ 
{ 
'name':'', 
'number:'', 
'department':'' 
} 
] 

而且我的JavaScript:

(function(){ 
    use strict'; 
      var module = angular.module('app', ['onsen']); 

      module.controller('AppController', function($scope, $data) { 
      $scope.doSomething = function() { 
       setTimeout(function() { 


    ons.notification.alert({ message: 'tapped' }); 
      }, 100); 
     }; 
     }); 



module.controller('DetailController', function($scope, $data) { 
    $scope.item = $data.selectedItem; 
    }); 

    module.controller('MasterController', function($scope, $data) { 
    $scope.items = $data.items; 

    $scope.showDetail = function(index) { 
     var selectedItem = $data.items[index]; 
     $data.selectedItem = selectedItem; 
     $scope.navi.pushPage('detail.html', {title : selectedItem.title}); 
    }; 
    }); 

    module.factory('$data', function() { 
     var data = {}; 

     data.items = [ 
      { 
       title: 'Noor almosswi', 
       label: '', 
       desc: 'Working in Managment', 
       phone: '0000', 
       photo:'http://cdn2.hubspot.net/hub/63072/file-14997515-jpg/images/jeremywilcomb_thedanielgroup.jpg?t=1430422772606&width=229&height=229' 
      }, 
      { 
       title: 'Safe khalid', 
       label: '', 
       desc: 'Working in accounting', 
       phone: '00000', 
       photo:'http://localhost/workflow/photos/c0d179d424ae9c327609c5d80e94c6e0_thumb.jpg' 
      }, 
      { 
       title: 'Yussif ali', 
       label: '', 
       desc: 'Working in Development', 
       phone: '0000', 
       photo:'http://www.beyondcareersuccess.com/wp-content/uploads/2012/08/employee.png' 
      }, 
      { 
       title: 'Ali kreeam', 
       label: '', 
       desc: 'Working in call center', 
       phone: '000000', 
       photo:'http://www.piranhaphotography.com/blog/wp-content/uploads/2010/05/brookfield-employee-portrait-photograph-0366.jpg' 
      } 
     ]; 

     return data; 
    }); 
})(); 

回答

0

在您的工廠,你可以只使用

$http.get('url').then(function(data){}); 

確保你注入$ HTTP以及

+0

非常感謝 –