typescript - Ionic 3 - 在警报控制器中设置 id 值
问题描述
是否可以id
在离子 3 的警报控制器中设置值?
通常在 html 标签中我们可以设置id
值。但是在这里显示警报对话框时,我们在 ts 代码中使用警报控制器。那么有什么方法可以id
在警报控制器中设置吗?
解决方案
尝试以下示例并在此处查看文档
import { AlertController } from 'ionic-angular';
constructor(private alertCtrl: AlertController) {
}
presentAlert() {
let alert = this.alertCtrl.create({
title: 'Low battery',
subTitle: '10% of battery remaining',
buttons: ['Dismiss']
});
alert.present();
}
presentConfirm() {
let alert = this.alertCtrl.create({
title: 'Confirm purchase',
message: 'Do you want to buy this book?',
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'Buy',
handler: () => {
console.log('Buy clicked');
}
}
]
});
alert.present();
}
presentPrompt() {
let alert = this.alertCtrl.create({
title: 'Login',
inputs: [
{
name: 'username',
placeholder: 'Username'
},
{
name: 'password',
placeholder: 'Password',
type: 'password'
}
],
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: data => {
console.log('Cancel clicked');
}
},
{
text: 'Login',
handler: data => {
if (User.isValid(data.username, data.password)) {
// logged in!
} else {
// invalid login
return false;
}
}
}
]
});
alert.present();
}
推荐阅读
- spring - spring 是否支持从 spring cloud config/http url 加载 bootstrap.yml 文件?
- java - Do service layer always must be transactional in spring?
- asp.net - 当 OnTextChanged 发生在中继器内时,触发按钮单击
- android - 无法从 WebView 访问相机
- angular5 - 如何在 ngOnInit 中优先订阅而不是随机执行?
- javascript - reactjs app fetch() 返回移动 html
- android - Do I need seperate library with native function in order to load library with main function?
- excel - How to make excel random selector not choose the same thing twice?
- c# - OpenFileDialog 不断显示 .lnk 文件 WPF
- c# - 将 X 值映射到 LiveCharts 中的字符串