如何重新加载 Angularjs 中提交按钮的页面点击?

How Can I Reload the Page Onclick of Submit Button in Angularjs?

大家好,我在我的应用程序中使用 MEAN 堆栈,AngularJS 作为我的前端。我怎样才能Reload Page onclick of Submit button。如果有人知道解决方案,请帮助我们。

我使用代码 reload the page 如下:-

在我使用的控制器中:-

sryarnpayment.$save(function(response) {
  $location.path('sryarnpayments/' + response._id, {}, { reload: true });

     $scope.name = '';
      }, function(errorResponse) {
        $scope.error = errorResponse.data.message;
     });
   };

在HTML中:-

<div class="controls">

      <input type="submit" class="btn btn-default">

  </div>

只需将其添加到 onClick 或 Sumitform In button

onclick="window.location.reload()"

要在点击或提交时重定向页面,请使用

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

$scope.method = function () {

    //Form Submission
        $http({
            method: 'POST',
            url: url,
            data: data,
        })
          .success(function (response) {
            if (response.status == true)
            {
                $window.location.href = base_url;
            }

        });
     };

    // For onClick:
      $scope.method = function() {
       $window.location.href = base_url;
     }
 });

在您的控制器中添加依赖项 $window。

这可能对您有所帮助。

改变$location.path('sryarnpayments/' + response._id, {}, { reload: true });

ui-路由器:

$state.go('STATE_NAME', { id: response._id});

ng-路线:

$location.path('/sryarnpayments/' + response._id);

假设你已经定义了路线(下面的例子)这应该有效

示例 - 路由定义

ui-路由器:

$stateProvider
.state('STATE_NAME', {
  url: "/sryarnpayments/:id",
  templateUrl: "partials/myPage.html",
  controller: newController
})

ng-路线:

config(['$routeProvider', function ($routeProvider) {
    $routeProvider.when('/sryarnpayments/:id', {
        templateUrl: 'path/myPage.html',
        controller: newController
    });
}]);

然后可以在newController中访问参数如下:

ui-路由器:

var id = $stateParams.id;

ng-路线:

var id = $routeParams.id;