2017-10-04 5 views
3

ボタンをクリックすると翻訳機能が呼び出される平均スタックアプリケーションがあります。ボタンがクリックされると、それはこの機能に入りますが、それはエラーをスローhttp.get一部を実行することはできません。角度js - TypeError:未定義のプロパティ 'get'を読み取ることができません

TypeError: Cannot read property 'get' of undefined

以下は、そのページのための私の角度のコードです。

(function() { 
    var app = angular.module('dashboard', []); 
    app.config(['$stateProvider', function($stateProvider) { 
     $stateProvider.state('secured.dashboard', { 
      url: '/dashboard', 
      controller: 'searchController', 
      templateUrl: '/views/dashboard.html' 
     }); 
    }]); 

    app.controller('searchController', ['$scope', 'AuthService', '$state', '$http', function($scope, AuthService, user, $state, $http) { 
     console.log($scope.user) 
     // AuthService.setUser(user); 
     console.log("In search controller"); 
     $scope.logout = function() { 
      AuthService.logout().then(function() { 
       $scope.user = null; 
       $state.go('unsecured'); 
      }) 
     } 

     $scope.data = {}; 

     $scope.translate = function() { 
      console.log("Entered") 
      console.log($scope.item); 
      $scope.show_results = true; 

      $http.get('/mosesTranslateSmall', { params: { name: $scope.item }, timeout: 600000 }). 
      then(function(response) { 
       console.log(response.data); 
       $scope.data.moses_less = response.data; 

      }); 

コントローラでhttpを引数として渡すことに関するアドバイスがありましたが、それでもやはりエラーが発生します。依存関係の

答えて

1

ご注文は間違っている、

app.controller('searchController', ['$scope', 'AuthService', '$state', '$http', function($scope, AuthService, $state, $http) { 
+0

のparamsのおかげで第二の組からuserを削除します。コントローラーと関数の議論で議論の順序が同じでなければならないのでしょうか? – Tarun

+1

はいそれは同じでなければなりません – Sajeetharan

+0

ええ、まず私は特定の時間の後にそれをマークすることができます私を示していた。私は今それをやった。ありがとう – Tarun

関連する問題