6.搜索页与首页对接
6.1 需求分析
用户在首页的搜索框输入关键字,点击搜索后自动跳转到搜索页查询
6.2 代码实现
6.2.1 首页传递关键字
修改 pinyougou-portal-web 的 contentController.js
//搜索跳转
$scope.search=function(){ location.href="http://localhost:9104/search.html#?keywords="+$scope.keywords;
}
修改 pinyougou-portal-web 的 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>[/size][/font][/align][align=left][font=微软雅黑][size=3]</div>
6.1.1 搜索页接收关键字
修改 pinyougou-search-web 的 searchController.js
添加 location 服务用于接收参数
app.controller('searchController',function($scope,$location,searchService){
......
接收参数并进行查询
//加载查询字符串
$scope.loadkeywords=function(){
$scope.searchMap.keywords= $location.search()['keywords'];
$scope.search();
}