A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

6.搜索页与首页对接
6.1 需求分析
用户在首页的搜索框输入关键字,点击搜索后自动跳转到搜索页查询
6.2 代码实现
6.2.1 首页传递关键字
修改 pinyougou-portal-web 的 contentController.js
[AppleScript] 纯文本查看 复制代码
//搜索跳转

$scope.search=function(){ location.href="http://localhost:9104/search.html#?keywords="+$scope.keywords;
}
修改 pinyougou-portal-web 的 index.html
[AppleScript] 纯文本查看 复制代码
<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 服务用于接收参数
[AppleScript] 纯文本查看 复制代码
app.controller('searchController',function($scope,$location,searchService){
......
接收参数并进行查询
[AppleScript] 纯文本查看 复制代码
//加载查询字符串

$scope.loadkeywords=function(){

$scope.searchMap.keywords=    $location.search()['keywords'];

$scope.search();

}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马