Javascript 使用Angular 2在HTML5中动态定义输入类型
下面的代码似乎不起作用。在Angular 2中可能吗Javascript 使用Angular 2在HTML5中动态定义输入类型,javascript,html,angular,Javascript,Html,Angular,下面的代码似乎不起作用。在Angular 2中可能吗 <table class="table table-responsive" style="border:0"> <tr *ngFor="#column of columns" style="height:20px;"> <td class="text-right" style="padding-top:10px;border:0"> <h4> {{column
<table class="table table-responsive" style="border:0">
<tr *ngFor="#column of columns" style="height:20px;">
<td class="text-right" style="padding-top:10px;border:0">
<h4> {{column | case}}: </h4>
</td>
<td class="text-center" style="padding-top:10px;border:0">
<input type="{{column == 'created_date' ? date : text}}" class="form-control" />
</td>
</tr>
</table>
{{column | case}}:
试试这个:
<input type="{{column == 'created_date' ? 'date' : 'text'}}" class="form-control" />
注意日期和时间周围的引号
如果没有引号,
日期
和时间
将被视为范围变量。并且将使用它们的值(如果已定义)。您似乎对字符串字段有输入错误。将代码更改为:
type="{{column == 'created_date' ? 'date' : 'text'}}"
由于类型
变量的值应为字符串,因此需要在其周围加引号,否则,它们将被视为在关联范围中定义的变量
因此,最终输出将是:
<input type="{{column == 'created_date' ? 'date' : 'text'}}" class="form-control" />