首页 > 解决方案 > $rootScope.$digest 正在清除参数

问题描述

我的方法有问题window.history.pushState。我在页面上https://localhost:1234/jobs。我想在不重新加载页面的情况下向我的 url 添加一个参数和哈希。我有一个简单的按钮来编辑工作:

<i class="fas fa-edit fa-fw"
   data-tooltip="tooltip"
   title="Edit this job"
   ng-click="goJobModal(job.id);$event.stopPropagation()"></i>

按此后,goJobModal应执行job.id

$scope.goJobModal = function(jobId) {
  if (jobId) {
    window.history.pushState(null, "Updating job", "/jobs/?jobId=" + jobId + "#update");
    console.log(window.location.href);
  } else {
    window.history.pushState(null, "Creating job", "/jobs#create");
  }
};

我放置了一个断点console.log来查看 pushState 之后会发生什么,我看到了一些对我来说很有趣的东西。在$rootScope.$digest我的网址被清除为https://localhost:1234/jobs. 我应该怎么做才能成功更改我的网址?

标签: javascriptangularjspushstateangularjs-digest

解决方案


推荐阅读