gpt4 book ai didi

javascript - Angular js - TypeError : Cannot read property 'get' of undefined

转载 作者:行者123 更新时间:2023-11-30 21:06:19 24 4
gpt4 key购买 nike

我有一个 mean stack 应用程序,点击一个按钮,翻译功能被调用。单击按钮时,它进入此函数,但随后无法执行抛出错误的 http.get 部分:

TypeError: Cannot read property 'get' of undefined

下面是该页面的 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;

});

我看过类似的问题,建议在 Controller 中将 http 作为参数传递,但我这样做了,但它仍然会引发错误。

最佳答案

你的依赖顺序错误,从第二组参数中移除user

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

关于javascript - Angular js - TypeError : Cannot read property 'get' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46557272/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com