我有一个$scope.product变量.在我看来,我有这个:
<a ng-href="/{{ gender }}/{{ section }}/{{ product.slug }}">{{ product.name }}</a>
Run Code Online (Sandbox Code Playgroud)
如果$scope.product.vendor存在,我希望它显示
{{ product.vendor.name }} - {{ product.name}} 例如:VendorName - ProductName
别的,只是表明
{{ product.name }} 例如:ProductName
我如何在视图中执行此操作?或者应该在其他地方完成?
PS是我的HTML的简化版本.我已经为周围的div有另一个变量的switch语句,所以这实际上是这样的:
<h3 ng-switch="locale">
<a ng-href="/{{ locale }}/{{ gender }}/{{ section }}/{{ product.slug }}" ng-switch-when="cn">{{ product.name }}</a>
<a ng-href="/{{ gender }}/{{ section }}/{{ product.slug }}" ng-switch-default>{{ product.name }}</a>
</h3>
Run Code Online (Sandbox Code Playgroud)
您可以在数据绑定中使用三元运算符:
<a ng-href="/{{ gender }}/{{ section }}/{{ product.slug }}">
{{(product.vendor.length > 0) ? product.vendor.name + ' - ' + product.name : product.name}}
</a>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7155 次 |
| 最近记录: |