[英]Evaluating if statement in brackets and assigning to HTML tag
I have a ng-repeat that has an array in an object. 我有一个在对象中具有数组的ng-repeat。 ex:
contract.fields[4]
. 例如:
contract.fields[4]
。
<tbody data-ng-repeat="(contractIndex,contract) in contracts">
<tr>
<td>
<div data-strat-form-control
data-field-display-id="1"
data-vmformreadonly="true"
data-show-tool-tip="showToolTip(contract.fields[3].htmlName)"
data-strat-model="contract"
data-field="contract.fields[1]">
</div>
</td>
<td>
<div data-strat-form-control
data-field-display-id="1"
data-vmformreadonly="true"
data-show-tool-tip="showToolTip(contract.fields[4].htmlName)"
data-strat-model="contract"
data-field="contract.fields[3]">
</div>
</td>
</tr>
</tbody>
I want to ad in aan if statement so that a different contract.fields array location will go under data-field tag. 我想在if语句中做广告,以便将另一个contract.fields数组位置放到data-field标签下。
<div data-strat-form-control
data-field-display-id="1"
data-vmformreadonly="true"
data-show-tool-tip="showToolTip(contract.fields[3].htmlName)"
data-strat-model="contract"
data-field="{{contract.COMMIT_CONTRACT.length > 1 | 'contract.fields[1]' : 'contract.fields[2]'}}">
</div>
Here is the bracket notation separately: 这是单独的括号符号:
{{contract.COMMIT_CONTRACT.length > 1 | 'contract.fields[1]' : 'contract.fields[2]'}}
Something is wrong with this code but it looks like I am doing something wrong. 这段代码有问题,但是看起来我做错了。 What is it and how do I fix it?
这是什么,我该如何解决?
Your expression seems wrong. 您的表情似乎不对。 First you don't need {{}} inside the data-field attribute.
首先,您不需要在data-field属性内使用{{}}。 Then single apices should be removed.
然后应去除单个顶点。 Then it seems you want to use a ternary operator but that syntax is wrong.
看来您想使用三元运算符,但是语法错误。 I think your expression should be simply:
我认为您的表达应该简单:
contract.COMMIT_CONTRACT.length > 1 ? contract.fields[1] : contract.fields[2]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.