英文:
If else statement is not displaying the textbox properly
问题
I am comparing two conditions here and trying to display a textbox based on the condition.
如果两个日期匹配并且任务也相同,那么我需要根据数据库中已输入的内容显示文本框,如果没有输入,则需要显示一个空文本框。但它没有起作用。有人可以帮我吗?
<div *ngFor="let userTimesheet of timesheet">
<div *ngIf="(((currentSun | date:'MM/dd/yyyy') === (userTimesheet?.task_date | date:'MM/dd/yyyy')) && (user.task.task_id == userTimesheet?.task)) else notMatching ">
<input type="text" value="{{ userTimesheet.task_totaleffort}}" formControlName="sundaytime">
</div>
<ng-template #notMatching>
<input type="text" value="" formControlName="sundaytime">
</ng-template>
</div>
请注意,这是您提供的代码的翻译部分。
英文:
I am comparing two conditions here and trying to display a textbox based on the condition.
If two dates are matching and task also same then i have to display the time entered in the textbox from database if it is already entered, if not i need to display am empty text box. But its not working. Can any one please help me?
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
<div *ngFor="let userTimesheet of timesheet">
<div *ngIf="(((currentSun | date:'MM/dd/yyyy') === (userTimesheet?.task_date | date:'MM/dd/yyyy')) && (user.task.task_id == userTimesheet?.task))); else notMatching " >
<input type="text" value="{{ userTimesheet.task_totaleffort}}" formControlName="sundaytime">
</div>
<ng-template #notMatching>
<input type="text" value="" formControlName="sundaytime">
</ng-template>
</div>
<!-- end snippet -->
答案1
得分: 1
您可以直接在`input`的value属性中使用三元运算符:
<div *ngFor="let userTimesheet of timesheet">
<input
type="text"
[value]="(((currentSun | date:'MM/dd/yyyy') === (userTimesheet?.task_date | date:'MM/dd/yyyy')) && (user.task.task_id == userTimesheet?.task)))
? userTimesheet.task_totaleffort : ''"
formControlName="sundaytime">
</div>
英文:
You could directly use a ternary operator in the input
value attribute :
<div *ngFor="let userTimesheet of timesheet">
<input
type="text"
[value]="(((currentSun | date:'MM/dd/yyyy') === (userTimesheet?.task_date | date:'MM/dd/yyyy')) && (user.task.task_id == userTimesheet?.task)))
? userTimesheet.task_totaleffort : ''"
formControlName="sundaytime">
</div>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论