我有一个平均堆栈应用程序,点击一个按钮,正在调用translate函数。单击该按钮时,它会进入此功能,但之后无法执行导致错误的(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;
});
部分:
TypeError:无法读取未定义的属性'get'
以下是该页面的角度代码。
{{1}}
我已经查看了类似的问题,这些问题建议将http作为参数传递给控制器,但是这样做仍然会引发错误。
答案 0 :(得分:1)
您的依赖顺序错误,请从第二组参数中删除 user
app.controller('searchController', ['$scope', 'AuthService', '$state', '$http', function($scope, AuthService, $state, $http) {