Input之AutoComplete

--自动完成功能是输入组件,提供实时的建议当打字。

Import

import {AutoCompleteModule} from 'primeng/primeng';

demo code

<h3 class="first">Basic</h3>
<p-autoComplete [(ngModel)]="country" [suggestions]="filteredCountriesSingle" (completeMethod)="filterCountrySingle($event)" field="name" [size]="30"
placeholder="Countries" [minLength]="1"></p-autoComplete>
<span style="margin-left:10px">Country: {{country ? country.name||country : 'none'}}</span> <h3>Advanced</h3>
<p-autoComplete [(ngModel)]="brand" [suggestions]="filteredBrands" (completeMethod)="filterBrands($event)" [size]="30"
[minLength]="1" placeholder="Hint: type 'v' or 'f'" [dropdown]="true" (onDropdownClick)="handleDropdownClick($event)">
<ng-template let-brand pTemplate="item">
<div class="ui-helper-clearfix" style="border-bottom:1px solid #D5D5D5">
<img src="showcase/resources/demo/images/car/{{brand}}.gif" style="width:32px;display:inline-block;margin:5px 0 2px 5px"/>
<div style="font-size:18px;float:right;margin:10px 10px 0 0">{{brand}}</div>
</div>
</ng-template>
</p-autoComplete>
<span style="margin-left:50px">Brand: {{brand||'none'}}</span> <h3>Multiple</h3>
<p-autoComplete [(ngModel)]="countries" [suggestions]="filteredCountriesMultiple" (completeMethod)="filterCountryMultiple($event)" styleClass="wid100"
[minLength]="1" placeholder="Countries" field="name" [multiple]="true">
</p-autoComplete>
<ul>
<li *ngFor="let c of countries">{{c.name}}</li>
</ul>

html

export class AutoCompleteDemo {

    country: any;

    countries: any[];

    filteredCountriesSingle: any[];

    filteredCountriesMultiple: any[];

    brands: string[] = ['Audi','BMW','Fiat','Ford','Honda','Jaguar','Mercedes','Renault','Volvo','VW'];

    filteredBrands: any[];

    brand: string;

    constructor(private countryService: CountryService) { }

    filterCountrySingle(event) {
let query = event.query;
this.countryService.getCountries().then(countries => {
this.filteredCountriesSingle = this.filterCountry(query, countries);
});
} filterCountryMultiple(event) {
let query = event.query;
this.countryService.getCountries().then(countries => {
this.filteredCountriesMultiple = this.filterCountry(query, countries);
});
} filterCountry(query, countries: any[]):any[] {
//in a real application, make a request to a remote url with the query and return filtered results, for demo we filter at client side
let filtered : any[] = [];
for(let i = 0; i < countries.length; i++) {
let country = countries[i];
if(country.name.toLowerCase().indexOf(query.toLowerCase()) == 0) {
filtered.push(country);
}
}
return filtered;
} filterBrands(event) {
this.filteredBrands = [];
for(let i = 0; i < this.brands.length; i++) {
let brand = this.brands[i];
if(brand.toLowerCase().indexOf(event.query.toLowerCase()) == 0) {
this.filteredBrands.push(brand);
}
}
} handleDropdownClick() {
this.filteredBrands = []; //mimic remote call
setTimeout(() => {
this.filteredBrands = this.brands;
}, 100)
}
}

ts

@Injectable()
export class CountryService { constructor(private http: Http) {} getCountries() {
return this.http.get('showcase/resources/data/countries.json')
.toPromise()
.then(res => <any[]> res.json().data)
.then(data => { return data; });
}
}

services

参考:

https://www.primefaces.org/primeng/#/autocomplete

PrimeNG之Input(一)的更多相关文章

  1. PrimeNG之Validation

    Validation ----primeng输入组件显示验证错误时自动标记为无效值. demo code export class ValidationDemo implements OnInit { ...

  2. PrimeNG之DataTable

    --数据表显示在表格格式数据. Basic Import import {DataTableModule,SharedModule} from 'primeng/primeng'; source &l ...

  3. PrimeNG之TreeTable

    --treetable用于显示分层数据表格的格式 Import import {TreeTableModule,TreeNode,SharedModule} from 'primeng/primeng ...

  4. angular项目中使用Primeng

    1.第一步把依赖添加到项目中 npm install primeng --save npm install @angular/animations --save npm install font-aw ...

  5. angular cli + primeNG

    目录: 1.安装  angular cli 2.创建项目 3.构建路由 4.新建组件 5.组件之间的通信 6.引入primeNG 7.修改primeNG组件样式 8.问题 -------------- ...

  6. HTML中上传与读取图片或文件(input file)----在路上(25)

    input file相关知识简例 在此介绍的input file相关知识为: 上传照片及文件,其中包括单次上传.批量上传.删除照片.增加照片.读取图片.对上传的图片或文件的判断,比如限制图片的张数.限 ...

  7. HTML5 input元素新的特性

    在HTML5中,<input>元素增加了许多新的属性.方法及控件.本文章分别对这三方面进行介绍. 目录 1. 属性 2. 方法 3. 新控件 1. 属性 <input>元素在H ...

  8. input[tyle="file"]样式修改及上传文件名显示

    默认的上传样式我们总觉得不太好看,根据需求总想改成和上下结构统一的风格…… 实现方法和思路: 1.在input元素外加a超链接标签 2.给a标签设置按钮样式 3.设置input[type='file' ...

  9. input标签中button在iPhone中圆角的问题

    1.问题 使用H5编写微信页面时,使用<input type="button"/>时,在Android手机中显示正常,但是在iPhone手机中则显示不正常,显示为圆角样 ...

随机推荐

  1. 第二周 数据分析之展示 Matplotlib基础绘图函数实例

    Pyplot基础图表函数 Pyplot饼图的绘制: Pyplot直方图的绘制: Pyplot极坐标图的绘制: Pyplot散点图的绘制: 单元小结: import numpy as np import ...

  2. 【原创】大叔问题定位分享(22)hive同时执行多个insert overwrite table只有1个可以执行

    hive 2.1 一 问题 最近有一个场景,要向一个表的多个分区写数据,为了缩短执行时间,采用并发的方式,多个sql同时执行,分别写不同的分区,同时开启动态分区: set hive.exec.dyna ...

  3. Apache JMeter压力测试实例

    脚本录制 脚本录制,JMeter启用WEB代理,浏览器把代理上网设置为JMeter所在的IP地址,自己电脑就是127.0.0.1代理端口默认8080.至于浏览器修改代理上网服务器,不做截图. Jmet ...

  4. jquery 查找子窗口

    $("#订单信息").contents().find('div.datagrid-body').hide();$("#订单信息").contents().fin ...

  5. javascript中字符串的方法

    字符串的方法 charAt();返回字符串指定索引的字符: concat();连接两个或多个字符串: indexOf();返回字符串中检索指定字符第一次出现的位置: lastIndexOf();返回字 ...

  6. SQL 概述

    SQL是用于在数据库中存储,操作和检索数据的标准语言. 本教程教你如何使用SQL:MySQL,SQL Server,MS Access,Oracle,Sybase,Informix,Postgres和 ...

  7. 快速启动FTP下载服务器

    nohup python -m SimpleHTTPServer 8000  > myout.file 2>&1 &

  8. 关于 永恒之蓝 和 MS17-010 补丁

    [KB4012598]:http://www.catalog.update.microsoft.com/Search.aspx?q=KB4012598 适用于Windows XP 32位/64位/嵌入 ...

  9. 有标号的DAG计数I~IV

    题解: https://www.cnblogs.com/zhoushuyu/p/10077241.html 看到这么一篇,发现挺不错的..

  10. Ios还是安卓的判断

    最近在做app的h5页面,涉及到一些小知识点 记录一下 1.微信屏蔽了下载的链接,所以在网页中添加的下载链接都要在浏览器中打开,这里需要一个提示用户在浏览器打开的提示弹框 //判断是否在微信终端打开 ...