2016-04-07 26 views
0

AngularJS'den rahat bir hizmet arıyorum. HTML bir giriş metin kutusu ve sorgu için bir düğme ile çok basittir.AngularJS çağrısı Dinlenme Api: TypeError

// basic.html

<!DOCTYPE html> 
<html ng-app="cgApp" > 
    <head> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular-resource.js"></script> 
    <script src="../js/controller.js"></script> 
    <script src="../js/service.js"></script> 

    </head> 
    <body> 
    <div ng-controller="CgseqCtrl"> 
     <input ng-model="analysisid"><button ng-click="searchById()">Search</button> 
     <table> 
      <tr> 
       <td>{{seq.analysisId}}</td> 
       <td>{{seq.center}}</td> 
       <td>{{seq.diseaseAbbr}}</td> 
       <td>{{seq.filepath}}</td> 
       <td>{{seq.library}}</td> 
      </tr> 
     </table>   
    </div> 
    </body> 
</html> 

ben REST API aranacak bir hizmeti kullanmak

// service.js 
app.factory("Cgseq", function ($http) { 
    // return $resource('http://localhost:8080/cgweb/api/seqs/fdebfd6e-d046-4192-8b97-ac9f65dc2009'); 
    var service = {}; 
    service.getSeqById = function(analysisid) { 
     return http.get('http://localhost:8080/cgweb/api/seqs/' + analysisid); 
    } 


    service.getSeq = function() { 
     return $http.get('http://localhost:8080/cgweb/api/seqs/fdebfd6e-d046-4192-8b97-ac9f65dc2009'); 
    } 

    return service; 
}); 

düğmesi tıklandığında kez searchById() çalıştırılacaktır fonksiyonu. Kontrol cihazımda uygulandı.

angular.js:12416 TypeError: $scope.searchById is not a function 
    at new <anonymous> (controller.js:8) 
+1

$ scope.searchById = function() {....} kullanmayı deneyin. Bu sorunun çözüleceğini umuyorum. –

cevap

2

Sen () kaldırması gerekir:

// controller.js 
var app = angular.module('cgApp', []) 

app.controller('CgseqCtrl', ['$scope', 'Cgseq', function($scope, Cgseq){ 
    $scope.searchById() = function() { 
     CgSeq.getSeqById($scope.analysisid) 
     .then(function(response){ 
      $scope.seq = response; 
     }); 
    } 
}]); 

ben giriş kutusuna şey yazmaya bile önce, bir tarayıcıda basic.html yük ve butonuna tıklayın

, aşağıdaki hata var

: $scope.searchById() = function

ve Cgseq Ie için yazım hatası (harf duyarlılığı) doğru gelen

İlgili konular