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.