Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Angular 2在HTML5中动态定义输入类型_Javascript_Html_Angular - Fatal编程技术网

Javascript 使用Angular 2在HTML5中动态定义输入类型

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

下面的代码似乎不起作用。在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 | 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" />