【发布时间】:2017-02-07 14:21:34
【问题描述】:
我正在尝试通过 URL 参数将 ID 传递给名为“more.html”的页面。所以 URL 参数将如下所示。
http://example.com/more.html?id=200
我在 more.html 页面上的控制器中使用 $location 服务从 URL 获取参数 ID。这是我使用的控制器代码。
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($location, $scope, $http) {
var sno = $location.search().id;
alert(sno);
});
我从上面的代码得到的结果是“Undefined”。
【问题讨论】:
-
尝试使用example.com/more.html#?id=200(添加'#'),但为什么不使用$state 而不是$location?一种更清洁和结构化的方法。 scotch.io/tutorials/angular-routing-using-ui-router
-
所以...可以使用
$state方法进行更改,不是吗?或更新网址。 -
那告诉我这种情况下如何使用$state?
-
如果你使用 angular-router 你可以通过使用 $routeParams 来实现
标签: angularjs