需求:用户在首页的搜索框输入关键字,点击搜索后自动跳转到搜索页查询
首页传递关键字
contentController.js:
//搜索跳转 $scope.search=function(){ location.href="http://localhost:9104/search.html#?keywords="+$scope.keywords; }
index.html
<div class="input-append"> <input type="text" id="autocomplete" type="text" ng-model="keywords" class="input-error input-xxlarge" /> <button class="sui-btn btn-xlarge btn-danger" ng-click="search()" type="button"> 搜索 </button> </div>
搜索页接收关键字
searchController.js:
添加 location 服务用于接收参数
app.controller('searchController',function($scope,$location,searchService){ ......
接收参数并进行查询
//加载查询字符串 $scope.loadkeywords=function(){ $scope.searchMap.keywords= $location.search()['keywords']; $scope.search(); }