我正在角度6中使用PrimeNg日历组件,并且希望实现带条件的[required]指令。 一旦我使用条件设置了“ required”,无论条件是什么,它总是设置为true。
<p-calendar
[required]="Item.status === 'In Transit'"
[(ngModel)]="Item.actualPickup" showTime="true"
hourFormat="24" showSeconds="true" dateFormat="dd/mm/yy"
[showIcon]="true" showButtonBar="true" hideOnDateTimeSelect="true">
</p-calendar>
您知道如何以模板驱动的形式执行此操作吗?
答案 0 :(得分:1)
要动态添加或删除{
"description": "Description of new product",
"title": "Title of new product",
"price": 200,
"pimages" : [
{
"path": "path to the image file"
}
]
}
属性:
Product p = new Product();
Pimage pi = new Pimage();
p.setDescription("Description from testcase");
p.setTitle("Title from testcase");
p.setPrice(50f);
pi.setPath("image path from testcase");
p.addPimage(pi);
Product saved= pr.save(p);
当条件为true时,将产生没有值的required
属性(由于<p-calendar [required]="Item.status === 'In Transit' ? '' : null">
):
required
否则,''
属性被完全遗漏了(由于<p-calendar required>
):
required
答案 1 :(得分:0)
* ngIf
总是在您对指令没有深入了解的情况下提供帮助。
使用
<p-calendar *ngIf = "myboolean == true"
[required]="Item.status === 'In Transit'"
[(ngModel)]="Item.actualPickup" showTime="true"
hourFormat="24" showSeconds="true" dateFormat="dd/mm/yy"
[showIcon]="true" showButtonBar="true" hideOnDateTimeSelect="true">
</p-calendar>
<p-calendar *ngIf = "myboolean == false"
[required]="Item.status = true"
[(ngModel)]="Item.actualPickup" showTime="true"
hourFormat="24" showSeconds="true" dateFormat="dd/mm/yy"
[showIcon]="true" showButtonBar="true" hideOnDateTimeSelect="true">
</p-calendar>