使用$ location更改位置

时间:2015-07-19 02:47:05

标签: javascript angularjs

当用户创建新文档时,我正在尝试将位置更改为编辑页面

所以我需要从#/pages/fp_add更改为#/pages/fp_add?id=

但以下两种情况都无法正常运作,

$location.path ('/pages/fp_add?id=' + id);
$location.path ('#/pages/fp_add?id=' + id);

我猜角度将它视为同一页面,有或没有参数?

有什么想法吗?它不会触发重新加载

附加路线配置,

app.config(function($routeProvider, $locationProvider) {
  $routeProvider.when('/pages/:name', {
    templateUrl: function(urlattr) {
      return 'templates/' + urlattr.name + '.html';
    },
    controller: function($scope, $routeParams, $controller) {
      $controller($routeParams.name, {
        $scope: $scope,
        $routeParams: $routeParams
      });
    }
  }).otherwise({
    redirectTo: '/pages/dashboard'
  });
});

3 个答案:

答案 0 :(得分:1)

为什么不尝试$ location.search function

$location.path('/pages/fp_add/').search({id: id});

<强>更新 我认为你应该使用这样的东西

.when('/pages/:name/:id', {

因此您可以接受 id 作为参数

答案 1 :(得分:0)

您可以使用$route.updateParams({ id: id})使用新参数重新加载当前路径,即使网址段相同也是如此。您需要将$ route服务作为依赖项。

答案 2 :(得分:0)

看起来正确的方法就是执行

  

location.href ='#/ pages / fp_add?id ='+ id

如果有一个有角度的方式,请告诉我

相关问题