采用NG-如果里面NG-重复? [英] Using ng-if inside ng-repeat?
本文介绍了采用NG-如果里面NG-重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我工作的角度应用程序。我试过NG-如果使用和交换机内的NG-重复,但没有成功。我有这样的数据:
i am working on Angular app. I tried to use ng-if and switch inside ng-repeat but didn't succeed. I have data like:
**[{"_id":"52fb84fac6b93c152d8b4569",
"post_id":"52fb84fac6b93c152d8b4567",
"user_id":"52df9ab5c6b93c8e2a8b4567",
"type":"hoot",},
{"_id":"52fb798cc6b93c74298b4568",
"post_id":"52fb798cc6b93c74298b4567",
"user_id":"52df9ab5c6b93c8e2a8b4567",
"type":"story",},
{"_id":"52fb7977c6b93c5c2c8b456b",
"post_id":"52fb7977c6b93c5c2c8b456a",
"user_id":"52df9ab5c6b93c8e2a8b4567",
"type":"article",},**
上面提到的搜索
$ scope.comments =数据
和我的HTML这样的:
$scope.comments = data mentioned above
and my Html like :
<div ng-repeat = "data in comments">
<div ng-if="hoot == data.type">
//differnt template with hoot data
</div>
<div ng-if="story == data.type">
//differnt template with story data
</div>
<div ng-if="article == data.type">
//differnt template with article data
</div>
</div>
我怎样才能实现这个角的东西?
How can i achieve this thing in Angular?
推荐答案
尝试以环绕字符串
(叱
, 的故事
,文章
)与报价
:
Try to surround strings
(hoot
, story
, article
) with quotes '
:
<div ng-repeat = "data in comments">
<div ng-if="data.type == 'hoot' ">
//different template with hoot data
</div>
<div ng-if="data.type == 'story' ">
//different template with story data
</div>
<div ng-if="data.type == 'article' ">
//different template with article data
</div>
</div>
这篇关于采用NG-如果里面NG-重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文