how to redirect using ng-click

后端 未结 3 1298
我在风中等你
我在风中等你 2021-01-02 10:08

Super-simple AngularJS app I\'m trying to build, to accept credentials into two text boxes, then use two-way binding to redirect on a button click to a url which includes th

3条回答
  •  伪装坚强ぢ
    2021-01-02 10:50

    Put a method on your controller to do the redirect and have that called form the ng-click on your button.

    Markup:

    
    

    Controller:

    .controller('LoginCtrl', function($scope, $location) {
        $scope.form = {
            username: null,
            password: null
        };
    
        $scope.goLogin = function() {
            $location.url('http://test.com/login.jsp?un='+ $scope.form.username +'&pw="+ $scope.form.password);
        };
    })
    

    Also note you want to call $location.url() not path()

    OR...

    Add $location to your scope and call url({{newUrl}}):

    $controller('MyCtrl', function($scope, $location) {
        $scope.$location = $location;
    })
    

    I'd still go with calling method on the scope.

提交回复
热议问题