【发布时间】:2018-03-15 09:34:55
【问题描述】:
我有一个平均堆栈应用程序,在单击按钮时,将调用翻译函数。单击按钮时,它进入此函数,但无法执行引发错误的http.get 部分:
TypeError: 无法读取未定义的属性“get”
以下是该页面的 Angular 代码。
(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 作为参数传递给控制器,但我正在这样做,但它仍然会引发错误。
【问题讨论】:
标签: javascript angularjs