这看起来像是爱奥尼亚的一个bug,但您仍然可以创建自己的自定义组件来“隐藏”涉及使用三个按钮的修复
*ngIf
并在页面中使用该自定义组件。
import { Component, ChangeDetectionStrategy, Input, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'custom-button',
template: `
<button (click)="onClick()" ion-button *ngIf="clear" clear>{{name}}</button>
<button (click)="onClick()" ion-button *ngIf="outline" outline>{{name}}</button>
<button (click)="onClick()" ion-button *ngIf="!clear && !outline">{{name}}</button>
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class CustomButtonComponent {
@Input()
public clear: boolean = false;
@Input()
public outline: boolean = false;
@Input()
public name: string;
@Output()
customClick: EventEmitter<void> = new EventEmitter<void>();
public onClick(): void {
this.customClick.next();
}
}
import { Component } from '@angular/core';
@Component({
selector: 'page-home',
template: `
<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<h2>Welcome to Ionic!</h2>
<ion-row>
<ion-col col-6>
<ion-label>
Using the custom component:
</ion-label>
</ion-col>
<ion-col col-2 *ngFor="let button of buttons">
<custom-button
[clear]="button.clear ? true : null"
[outline]="button.outline ? true : null"
[name]="button.name"
(customClick)="onClicked()">
</custom-button>
</ion-col>
</ion-row>
</ion-content>
`
})
export class HomePage {
public buttons: Array<any> = [
{ clear: true, outline: false, name: 'Clear' },
{ clear: false, outline: true, name: 'Outline' },
{ clear: false, outline: false, name: 'Default' }
];
public onClicked() {
console.log('Clicked!');
}
}