代码之家  ›  专栏  ›  技术社区  ›  Dreams

Angular js-TypeError:无法读取未定义的属性“get”

  •  1
  • Dreams  · 技术社区  · 8 年前

    我有一个平均堆栈应用程序,点击一个按钮,就会调用translate函数。单击按钮后,它将进入此功能,但随后无法执行 http.get 引发错误的部分:

    TypeError:无法读取未定义的属性“get”

    (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 回复  |  直到 8 年前
        1
  •  1
  •   Sajeetharan    8 年前

    您的依赖顺序错误,请删除 user

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