这是我第一次尝试使用离子2.但我已经遇到了困难.但我正在努力.所以在我开始一个新项目之后,我继续看看如何使用click事件.我在网上搜索和阅读.但仍然没有得到适当的答案.
所以我在按钮点击事件上使用了这个代码.
<button myitem (click)='openFilters()'>CLICK</button>
Run Code Online (Sandbox Code Playgroud)
我的.ts文件如下所示.
import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
@Component({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
constructor(private navCtrl: NavController) {
openFilters() {
console.log('crap');
}
}
}
Run Code Online (Sandbox Code Playgroud)
我事件尝试添加selector: 'myitem',到@component部分.
我正在使用Ionic 2进行编程,并且我想在单击按钮时显示弹出警报.
这是我home.html中的代码:
<button (click)='openFilters()'>CLICK</button>
Run Code Online (Sandbox Code Playgroud)
在我的家里
import {Component} from '@angular/core';
import {Page, NavController, Alert} from 'ionic-angular';
@Component({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
constructor(nav: NavController, alertCtrl: AlertController) {
}
openFilters() {
let alert = this.alertCtrl.create({
title: 'Low battery',
subTitle: '10% of battery remaining',
buttons: ['Dismiss']
});
alert.present();
}
}
Run Code Online (Sandbox Code Playgroud)
我已经阅读了关于这个主题的一些stackoverflow问题,并试图像这样实现它:
openFilters() {
let alert:Alert = Alert.create({
title: 'Low battery',
subTitle: '10% of battery remaining',
buttons: ['Dismiss']
});
this.nav.present(alert);
}
Run Code Online (Sandbox Code Playgroud)
我还没有完成任何事情; 我收到错误.