How to redirect to another page using AngularJS?

前端 未结 12 625
深忆病人
深忆病人 2020-11-27 11:04

I am using ajax call to perform functionality in a service file and if the response is successful, I want to redirect the page to another url. Currently, I am doing this by

12条回答
  •  情深已故
    2020-11-27 11:42

     (function () {
    "use strict";
    angular.module("myApp")
           .controller("LoginCtrl", LoginCtrl);
    
    function LoginCtrl($scope, $log, loginSrv, notify) {
    
        $scope.validateUser = function () {
            loginSrv.validateLogin($scope.username, $scope.password)
                .then(function (data) {
                    if (data.isValidUser) {
                        window.location.href = '/index.html';
                    }
                    else {
                        $log.error("error handler message");
                    }
                })
        }
    } }());
    

提交回复
热议问题