简体   繁体   中英

Angular js autocomplete search with link

I am trying to implement auto complete search with link(after selecting it should jump to particular page). only i need to hide the data appearing below search box, it should only display when user start type like search functionality works.

there are tow screen shot below, 1st one is what i have done where data is by default populated, so i want this to be hidden and when i type the it should display like screen2 在此处输入图片说明

数据是使用json从数据库中填充的,但是我需要在输入框后隐藏显示的内容,只有当我键入相关文本时,它才会出现

<!DOCTYPE html>
<html>
<head>
<title>Angular JS</title>

<style>
ul,li{margin:0; padding:0;}
</style>
</head>
<body>    
<div ng-app="myApp" ng-controller="movieCtrl"> 
<input type="text" ng-model="film">
<ul>
  <li ng-repeat="x in movies | filter:film | orderBy:'film'" style="list-style-type:none;"><a href="{{ x.param }}">{{ x.film  | uppercase }}</a></li>
</ul>

</div>    

<script src="Scripts/angular.min.js"></script>
<script>
var app = angular.module('myApp', []);
app.controller('movieCtrl', function($scope, $http) {
    $http.get("tmp.php")
    .success(function(response) {$scope.movies = response.movie;});
});
</script>
</body>
</html>

Add a condition to your list to only be visible if the filter is not empty:

<ul ng-show="film">
  <li ng-repeat="x in movies | filter:film | orderBy:'film'" style="list-style-type:none;"><a href="{{ x.param }}">{{ x.film  | uppercase }}</a></li>
</ul>

You add a variable (initially false) and hide your list based on that. Then when you change your input change the variable to true. here is what you can do:

<input type="text" ng-model="film" ng-init="show=0" ng-change="show=1">

and

<ul ng-show="show=1">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM