Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.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
Html 如何使用angular将单元格colspan基于条件值?_Html_Angularjs_Conditional_Html Table_Inline - Fatal编程技术网

Html 如何使用angular将单元格colspan基于条件值?

Html 如何使用angular将单元格colspan基于条件值?,html,angularjs,conditional,html-table,inline,Html,Angularjs,Conditional,Html Table,Inline,基于html页面其他地方的值,我需要在表中显示一行,以显示比表中其他地方更多的单元格。为了保持对齐正确和一切清洁,我正在寻找一种方法,使用angular动态设置单元格的colspan。我就是不能让它工作 <input type="checkbox" ng-model="vm.noInventory"/> <table> <th> <td>Product</td> <td colspan={{vm.no

基于html页面其他地方的值,我需要在表中显示一行,以显示比表中其他地方更多的单元格。为了保持对齐正确和一切清洁,我正在寻找一种方法,使用angular动态设置单元格的colspan。我就是不能让它工作

<input type="checkbox" ng-model="vm.noInventory"/>

<table>  
  <th>
     <td>Product</td>
     <td colspan={{vm.noInventory ? '2' : '1'}}>Inventory<td>
     <td ng-show="vm.noInventory"></td>
  </tr>
  <tr>
     <td>Product B</td>
     <td>55 parts</td>
     <td ng-show="vm.noInventory">Backordered</td>      
  </tr>

</table>

产品
库存
产品B
55部分
延期交货

找到了解决方案。。。事实上,我有一个拼写错误,需要在colspan中包含“”

<td colspan="{{vm.noInventory ? '2' : '1'}}">Inventory<td>
库存

如果您可以通过CSS设置colspan,另一种方法是利用并定义一个函数,该函数返回与您内联指定的对象类似的对象

例如,您可以将ng style指令添加到TD元素,如下所示:

<td ng-style=vm.colWidth(vm.noInventory)>Inventory<td>

如果您在动态生成表格行的角度工作,则可以使用以下命令
{{fieldsChanged.newValue}

谢谢!对于Angular 2,我是这样做的:
[attr.colspan]=“isTrueValue?”2':“0”
vm.colWidth = function(noInv) {
  return  {"colspan": noInv ? '2' : '1' };
};