zl程序教程

您现在的位置是:首页 >  其他

当前栏目

48分布式电商项目 - 搜索页与首页对接

搜索项目分布式分布式 电商 首页 对接 48
2023-09-11 14:15:41 时间

需求:用户在首页的搜索框输入关键字,点击搜索后自动跳转到搜索页查询

首页传递关键字

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();
		}