假设我当前的位置为/phones
我想路由到不同的控制器并生成类似/phonedetails?brand=x&size=y&price=z
如何设置路线和控制器?
//partial phonelist.html
<form id="phones-form">
<input id="brand" type="text" placeholder="brand" ng-model="phoneInfo.brand">
<input id="size" type="text" placeholder="size" ng-model="phoneInfo.size">
<input id="price" type="text" placeholder="price" ng-model="phoneInfo.price">
<button type="submit" class="btn btn-primary btn-lg" ng-click="getPhones()">Search</button>
</form>
//controller
$scope.phoneInfo = {};
$scope.getPhones() {
$location.search($scope.phoneInfo);
}
$location.search()
会生成一个类似/phones?brand=x&size=y&price=z
的网址,并且不会将控制转移到其他控制器。
也许我对路线的理解完全错了。实现这一目标的正确方法是什么?
答案 0 :(得分:2)
$location.search()
只会控制查询字符串。要更改位置,您需要使用$location.path()
。
$scope.getPhones() {
$location.search($scope.phoneInfo);
$location.path('/phonedetails');
}