ng-switch 放置元素
ng-switch to place elements
有什么更好的写法吗?我只是不想重复列表的内部内容两次。
<div ng-switch on="list.type">
<ul ng-switch-when="unorder">
<li ng-repeat="item in items">
{{ item.text }}
</li>
</ul ng-switch-when="unorder">
<ol ng-switch-when="order">
<li ng-repeat="item in items">
{{ item.text }}
</li>
</ol ng-switch-when="order">
</div>
<div>
<list content="list.type">
<li ng-repeat="item in items">
{{ item.text }}
</li>
</list>
</div>
使用数据绑定,您可以将列表指令模板更改为
<ul ng-transclude>
或<ol ng-transclude>
我认为使用 css 比使用自定义指令更简单
Html
<ol ng-class="{'no-style' : list.type === 'unorder'}">
<li ng-repeat="item in items">
{{ item.text }}
</li>
</ol>
CSS
ol.no-style {
list-style-type: none;
}
实例你可以看here
有什么更好的写法吗?我只是不想重复列表的内部内容两次。
<div ng-switch on="list.type">
<ul ng-switch-when="unorder">
<li ng-repeat="item in items">
{{ item.text }}
</li>
</ul ng-switch-when="unorder">
<ol ng-switch-when="order">
<li ng-repeat="item in items">
{{ item.text }}
</li>
</ol ng-switch-when="order">
</div>
<div>
<list content="list.type">
<li ng-repeat="item in items">
{{ item.text }}
</li>
</list>
</div>
使用数据绑定,您可以将列表指令模板更改为
<ul ng-transclude>
或<ol ng-transclude>
我认为使用 css 比使用自定义指令更简单
Html
<ol ng-class="{'no-style' : list.type === 'unorder'}">
<li ng-repeat="item in items">
{{ item.text }}
</li>
</ol>
CSS
ol.no-style {
list-style-type: none;
}
实例你可以看here