i have static table columns for each month and static table body columns as input text for each month.i am having a problem in creating logic to disable future month input text. thank in advance code of my html file
i want to disable input of future month for example november and december
CodePudding user response:
You need to add additional field in your static table for monthNumber. For ex: Jan = 1, Feb = 2, Mar = 3.....
After that in you component declare two new variable todaysDate
= todaysDate: Date = new Date();
and currentMonth
= currentMonth: any
Then create method to get current month as below
getMonth() {
this.month = this.todaysDate.getMonth() 1;
}
Call this method from ngOnInit()
, you will get current month.
After this in your HTML file add [disabled]
in your input fields
[disabled]="(i.month > currentMonth)"
CodePudding user response:
in angular you can use the property [disabled] on input field and call a component a method
for sample you can create a method and pass in parameter the monthNumber
<input [disabled]="isFutureMonth(0)"/> // for january
<input [disabled]="isFutureMonth(1)"/> /// for febrary
and in the component's controller we can propose you to :
stored somewhere the current month
create a method that check if input month is in the future or not enter code here
export class MyComponent {
currentMonth:number; constructor() { this.currentMonth = new Date().getMonth(); } isFutureMonth(monthNumber:number):boolean { return (monthNumber > this.currentMonth); }
}