【问题标题】:Redirection in location.path() AngularJS methodlocation.path() AngularJS 方法中的重定向
【发布时间】:2015-06-17 10:32:47
【问题描述】:

app.js

   .when('/ModifyStructure/{c}', {
            templateUrl: 'views/ModifyStructure.html',
            controller: 'ModifyStructureCTRL'
          }

方法

 $scope.editST = function (ids) {
         var c = ids.substring(1, 3);
         $location.path('http://localhost:8080/structure/ModifyStructure/' + c);
     }

为什么在执行此方法时,导航器会将我重定向到'/'路径?

【问题讨论】:

  • 尝试使用$location.path('/ModifyStructure/' + c);

标签: javascript angularjs rest spring-boot


【解决方案1】:

为什么在执行此方法时,导航器会将我重定向到'/'路径?

因为您要设置的不是路径,它是一个绝对 URL。但是,在文档中 explicitly states 在 Angular 中:

路径应始终以正斜杠(/)开头,如果缺少正斜杠,此方法将添加。

在你的情况下,你因为在路由配置中没有定义这样的路径,所以otherwise部分被执行,我假设它已经重定向到/。

您应该指定这样的路径:

$location.path('/ModifyStructure/' + c);

【讨论】:

  • ok 搞定了,问题是如何在 ModifyStructure.html 页面中获取“c”的值?
  • 在ModifyStructureCTRL 中使用$routeParams 服务。您可以将其公开到范围:$scope.c = $routeParams.c.
  • 使用 alert($routeParams.c) 后显示 "undefined" ??
  • 我觉得应该是.when('/ModifyStructure/:c', {
  • 显示“未定义”的问题是一样的??
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-04
  • 1970-01-01
  • 2017-04-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多