programing

AngularJS Reference Error: $window가 정의되지 않았습니다.

codeshow 2023. 10. 4. 23:06
반응형

AngularJS Reference Error: $window가 정의되지 않았습니다.

사용자가 양식 유효성 검사(데이터베이스 값과 비교하여 사용자 이름 및 암호 확인)를 통과하면 사용자에게 다시 지시를 내리려고 합니다.

유효성 검사는 잘 되지만 제 것에서는 잘 됩니다.리디렉션 성공 함수가 작동하지 않는 것 같습니다. 'ReferenceError: $window가 정의되지 않았습니다.'라는 오류가 표시됩니다.

코드는 다음과 같습니다.

.success(function(data) {
    console.log(data);

        if (!data.success) {
            // if not successful, bind errors to error variables
            $scope.errorUserName = data.errors.userName;
            $scope.errorUserPassword = data.errors.userPassword;
        } else {
            // if successful, bind success message to message
            $scope.message = data.message;
            $window.location=('twitter.com');       
    }
});

위치 이동 경로를 변경해 보았지만 아무 것도 작동하지 않는 것 같습니다.무슨 생각 있어요?

감사합니다!

레이지 토토로

$window주사를 맞아야 합니다.

주입하려면 컨트롤러 기능에 파라미터로 추가하면 Angular가 자동으로 나머지를 처리합니다.

예를 들어,

app.controller('MyController', function MyController($scope, $window) {

    $window.location = 'http://stackoverflow.com'
});

Angular에서 의존성 주입에 대한 자세한 내용을 읽을 수 있습니다.JS 여기.

전체 페이지를 다시 로드할 필요가 없다면 $location:

// get the current path
$location.path();

// change the path
$location.path('/newValue');

언급URL : https://stackoverflow.com/questions/23392714/angularjs-referenceerror-window-is-not-defined

반응형