我有一个带有Angular 2的Ionic 2应用程序,它有一个搜索栏,工作正常。每次用户在searchBar中输入一个字符时,它都会在.ts文件中运行一个更新结果的函数。但是,我设置了一个菜单按钮以在(点击)指令中启动不同的功能,并且控制台声明<ion-header>
<ion-navbar>
<ion-title>Merit Badges</ion-title>
<ion-buttons (click)="toggleAppearance()" end>
<button>
<ion-icon name="search"></ion-icon>
</button>
</ion-buttons>
<ion-buttons end>
<button>
<ion-icon name="more"></ion-icon>
</button>
</ion-buttons>
</ion-navbar>
</ion-header>
<ion-content>
<ion-searchbar (ionInput)="getItems($event)"></ion-searchbar>
<ion-list>
<ion-item *ngFor="let n of meritBadges">
{{n.title}}
</ion-item>
</ion-list>
</ion-content>
。
这是我的代码:
择优badges.html
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
templateUrl: 'build/pages/merit-badges/merit-badges.html',
})
export class MeritBadgesPage {
meritBadges: Array < {
title: string,
type: string
} > ;
let searchVisible: boolean = false;
constructor(private navCtrl: NavController) {
this.initializeItems();
}
getItems(ev) {
// Reset items back to all of the items
this.initializeItems();
// set val to the value of the ev target
var val = ev.target.value;
// if the value is an empty string don't filter the items
if (val && val.trim() != '') {
this.meritBadges = this.meritBadges.filter((meritBadge) => {
return (meritBadge.title.toLowerCase().indexOf(val.toLowerCase()) > -1);
});
}
}
toggleAppearance(){
console.log("APPEARANCE TOGGLED");
}
}
择优badges.ts
public void generatePDFDoc(Activity activity, View view, String pdfFileName){
{
File pdfFile = null;
PrintAttributes printAttrs = new PrintAttributes.Builder().
setColorMode(PrintAttributes.COLOR_MODE_COLOR).
setMediaSize(PrintAttributes.MediaSize.NA_LETTER).
setResolution(new PrintAttributes.Resolution("print", activity.PRINT_SERVICE,
25, 25)).
setMinMargins(PrintAttributes.Margins.NO_MARGINS).
build();
PdfDocument document = new PrintedPdfDocument(activity, printAttrs);
View content = view;
int width = content.getWidth();
int height = content.getHeight();
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(width, height, 1).create();
PdfDocument.Page page = document.startPage(pageInfo);
content.draw(page.getCanvas());
document.finishPage(page);
try {
pdfFile = new File(pdfFileName);
if (pdfFile != null) {
FileOutputStream os = new FileOutputStream(pdfFile);
document.writeTo(os);
document.close();
os.close();
}
} catch (Exception e) {
throw new RuntimeException("Error generating file", e);
} finally {
if (pdfFile != null) {
//Success Generate PDF file
}
}
}
}