admin管理员组文章数量:1399978
I have the following ponent:
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'app-button',
styleUrls: ['./buttonponent.scss'],
template: `
<ion-button color="{{color}}" (click)="action.emit(null)" [disabled]="condition">
{{title}}
</ion-button>
`
})
export class ButtonComponent implements OnInit {
@Input() public title: string;
@Input() public color = 'primary';
@Input() public condition: any;
@Output() public action = new EventEmitter();
constructor() { }
ngOnInit() {
}
}
But when I pass the boolean out of it it does not render, because I have a boolean that starts false and bees true according to the input.
edit: the problem is when validDocument bees true, the button does not render again and remains disabled.
HTML declaration:
<app-button title="Buscar" (action)="go()" condition="!validDocument"></app-button>
I have the following ponent:
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'app-button',
styleUrls: ['./button.ponent.scss'],
template: `
<ion-button color="{{color}}" (click)="action.emit(null)" [disabled]="condition">
{{title}}
</ion-button>
`
})
export class ButtonComponent implements OnInit {
@Input() public title: string;
@Input() public color = 'primary';
@Input() public condition: any;
@Output() public action = new EventEmitter();
constructor() { }
ngOnInit() {
}
}
But when I pass the boolean out of it it does not render, because I have a boolean that starts false and bees true according to the input.
edit: the problem is when validDocument bees true, the button does not render again and remains disabled.
HTML declaration:
<app-button title="Buscar" (action)="go()" condition="!validDocument"></app-button>
Share
Improve this question
edited Nov 11, 2019 at 12:51
Thales Henrique
asked Nov 11, 2019 at 12:16
Thales HenriqueThales Henrique
271 silver badge7 bronze badges
1
- try with [disabled]="{{condition}}" – manishgdev Commented Nov 11, 2019 at 12:20
4 Answers
Reset to default 2Have you tried:
@Component({
selector: 'app-button',
styleUrls: ['./button.ponent.scss'],
changeDetection: ChangeDetectionStrategy.OnPush, // force a ponent re-draw on input change
template: `
<ion-button color="{{color}}" (click)="action.emit(null)" [disabled]="condition">
{{title}}
</ion-button>
`
})
If you are just passing an @Input()
to the template you can change the changeStratergy
to OnPush
.
If you also want to use an @Input()
inside the ponent you can add ngOnChanges
to trigger functions that need to be fired when the @Input()
is changed.
https://angular.io/api/core/ChangeDetectionStrategy
OnPush
can speed up your app quite a bit if you have lots of ponents on the page at the same time
Try this code
<ion-button color="{{color}}" (click)="action.emit(null)" [disabled]="condition">
{{title}}
</ion-button>
How about
[attr.disabled]="condition ? '' : null"
instead of directly using disabled
. That should do the job.
try with below code
<ion-button color="{{color}}" (click)="action.emit(null)" disabled [attr.disabled]="(condition)?condition:null">
{{title}}</ion-button>
[attr.disabled] will remove the disabled attribute if condition value is found to be false
本文标签: javascriptHow to pass the disabled conditionin the ionic button componentStack Overflow
版权声明:本文标题:javascript - How to pass the disabled condition, in the ionic button component - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744185663a2594278.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论