If else语句未正确显示文本框。

huangapple go评论83阅读模式
英文:

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 -->

&lt;div *ngFor=&quot;let userTimesheet of timesheet&quot;&gt;
    &lt;div *ngIf=&quot;(((currentSun | date:&#39;MM/dd/yyyy&#39;) === (userTimesheet?.task_date | date:&#39;MM/dd/yyyy&#39;)) &amp;&amp; (user.task.task_id == userTimesheet?.task))); else notMatching &quot; &gt;
                &lt;input type=&quot;text&quot; value=&quot;{{ userTimesheet.task_totaleffort}}&quot; formControlName=&quot;sundaytime&quot;&gt;
    &lt;/div&gt;
	&lt;ng-template #notMatching&gt;
		&lt;input type=&quot;text&quot; value=&quot;&quot; formControlName=&quot;sundaytime&quot;&gt;
	&lt;/ng-template&gt;
&lt;/div&gt;

<!-- end snippet -->

答案1

得分: 1

您可以直接在`input`的value属性中使用三元运算符:

&lt;div *ngFor=&quot;let userTimesheet of timesheet&quot;&gt;
    &lt;input 
        type=&quot;text&quot; 
        [value]=&quot;(((currentSun | date:&#39;MM/dd/yyyy&#39;) === (userTimesheet?.task_date | date:&#39;MM/dd/yyyy&#39;)) &amp;&amp; (user.task.task_id == userTimesheet?.task))) 
            ? userTimesheet.task_totaleffort : &#39;&#39;&quot; 
        formControlName=&quot;sundaytime&quot;&gt;
&lt;/div&gt;
英文:

You could directly use a ternary operator in the input value attribute :

&lt;div *ngFor=&quot;let userTimesheet of timesheet&quot;&gt;
    &lt;input 
        type=&quot;text&quot; 
        [value]=&quot;(((currentSun | date:&#39;MM/dd/yyyy&#39;) === (userTimesheet?.task_date | date:&#39;MM/dd/yyyy&#39;)) &amp;&amp; (user.task.task_id == userTimesheet?.task))) 
            ? userTimesheet.task_totaleffort : &#39;&#39;&quot; 
        formControlName=&quot;sundaytime&quot;&gt;
&lt;/div&gt;

huangapple
  • 本文由 发表于 2020年1月6日 17:37:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/59609702.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定