2017-01-30 6 views
0

私はionicで実験しています(phonegapオンラインビルダーを使ってビルドしています)、私は今工場を追加しようとしていますが、それはうんざりして白い空白の画面を表示します。私は同様の問題で修正を試みました:How to use factories with Ionic/Angular JS with phonegap?イオンを使って工場を追加するには?

しかし、それでも動作しません。私services.jsファイルは次のようになります。

.factory('userFactory', [function() { 
var users = [ 
    {name: 'Omar', city: 'rizal'}, 
    {name: 'Ganny', city: 'makati'}, 
    {name: 'Chester', city: 'manila'} 
]; 
return { 
    getUsers: function(){ 
     return users; 
     }, 
    getUser: function(id){ 
     for(i=0;i<users.length;i++){ 
      if(users[i].name == id) 
      { 
       return users[i]; 
      } 
     } 
     return null; 
    } 
}; 
}]) 

と私のコントローラは次のようになります。コントローラに

angular.module('app.controllers', []) 

.controller('CityCtrl', ['$scope', '$stateParams', '$location' 
function ($scope, $stateParams, $location, userFactory) { 
$scope.userdata = {}; 
$scope.enterCity = function(usern,city) { 
    if(userFactory.getUser(usern) != null) 
    { 
     $location.path('/page14'); 
    } 
    else 
    { 
     alert('Failed'); 
    } 
} 

}]) 
+0

あなたでなければなりません'users'配列に' Username'プロパティを持つオブジェクトがないので、 'getUser()'は**常に** nullを返すでしょう。 – Claies

+0

ありがとう、私はそれを見ていない。 –

答えて

0

あなたdepdenceniesが正しくフォーマットされていない、それは

.controller('CityCtrl', ['$scope', '$stateParams', '$location','userFactory', 
function ($scope, $stateParams, $location, userFactory) { 
関連する問題