1

I have a mean stack application where on click of a button, translate function is being called. When the button is clicked, it enters this function, but then is not able to execute the http.get part where it throws the error :

TypeError: Cannot read property 'get' of undefined

Below is my angular code for that page.

(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;

            });

I have looked at similar questions which advice on passing http as an argument in the controller, but am doing that and it still throws an error.

1 Answer 1

1

Your order of dependency is wrong, remove user from the second set of params

   app.controller('searchController', ['$scope', 'AuthService', '$state', '$http', function($scope, AuthService, $state, $http) {
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. It worked, also, should the order of arguments be same in the arguments in controller and function?
Ya, first it was showing me i can only mark it after a specific time. I have done it now. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.