2016-04-06 24 views
0

Angularj'lerde yeniyim. Angularjs kullanarak bir mobil uygulama oluşturmaya çalışıyorum. Burada sadece if koşulu çalışıyor ve else çalışmaz, yani http ilk çalışmadığı sırada mükemmel çalışıyor. Bunu nasıl çözebilirim?AngularJS iki tane http istekleri döndürür, ancak sadece birincisi çözülür

Kuralların için Fiddle ve url güncelledik index.html

<button class="button button-icon" ng-click="loadlanguages('english')" > 
    en 
</button> 

<button class="button button-icon" ng-click="loadlanguages('malayalam')" > 
    ml 
</button> 
+0

Her şeyin iyi çalıştığı anlaşılıyor. Kodunuzu kontrol edebilmek için buna benzer bir [fiddle] (http://jsfiddle.net/hYACX/315/) yaptım. –

+0

Kodunuzda url.but ile mükemmel bir şekilde çalışıyorum, kodunuzda url'imi geçtiğimde çalışmaz.stillen sadece bir tanesi aynı hatayı gösteriyor henüz bir tane daha çalışıyor. (MJunaidSalaat – sherins

+0

@mJunaidSalaat Kodunuzda hiçbir değişiklik yapmadım sadece URL'yi değiştir .ama çalışmıyor. ingilizce.js ilk http üzerinde geçirirseniz ve çalışıyor ve malayalam.js çalışmıyor. ve malayalam.js'yi ilk http olarak geçiyorsa, çalışma ve english.js çalışmıyor – sherins

cevap

0

$http({method: 'JSONP', url: 'http://js/english.js?callback=JSON_CALLBACK'}). 
    then(function(response) { 
     console.log(response); 
     $scope.status = response.status; 
     $scope.templeEn = response.data; 
    }); 

$http({method: 'JSONP', url: 'http://js/malayalam.js?callback=JSON_CALLBACK'}). 
    then(function(response) { 
     console.log(response); 
     $scope.status = response.status; 
     $scope.templeMl = response.data; 
    }); 


$scope.loadlanguages=function(files) { 
    console.log(files); 
    if(files=='english') { 
     console.log('hai'); 
     $scope.result=$scope.templeEn; 
     console.log($scope.result);  
    } 
    else { 
     console.log('ml'); 
     $scope.result=$scope.templeMl; 
     console.log($scope.result) 
    } 
} 

app.js. Bu şimdi çalışmalı.

Lütfen kemanın sitenize erişmesine izin verilmeyeceğini ve cross-domain hatasını attığını unutmayın. Bunu devre dışı bırakmak ve verilerinizi kemanda getirmek için chrome extension kullandım. aşağıda güncellenmiş kod ve yanıt resminiz var.

enter image description here

$http.get("http://www.obidostech.com/english.js") 
     .then(function(json) { 
     $scope.responseFoo = json.data; 
     },function(err){ 
     console.log(err) 
     }); 

    $http.get("http://www.obidostech.com/malayalam.js") 
     .success(function(json) { 
     $scope.responseBar = json; 
     },function(err){ 
     console.log(err) 
     }); 

    $scope.response = []; 

    $scope.loadlanguages = function(lang){ 
     if(lang === 'foo'){ 
      $scope.response = $scope.responseFoo 
     } 
     else{ 
     $scope.response = $scope.responseBar; 
     } 
    }; 

yardımcı olur Umut.

+0

Yea Onunla başarılı bir şekilde çalışmak senin kodun .. .. :) :) – sherins