angularjs – 在ng-repeat中使用ng-if?
发布时间:2020-12-17 09:02:50 所属栏目:安全 来源:网络整理
导读:我正在工作的Angular应用程序。我试图使用ng-if和切换ng-repeat内,但没有成功。我有数据: **[{"_id":"52fb84fac6b93c152d8b4569","post_id":"52fb84fac6b93c152d8b4567","user_id":"52df9ab5c6b93c8e2a8b4567","type":"hoot",},{"_id":"52fb798cc6b93c7429
我正在工作的Angular应用程序。我试图使用ng-if和切换ng-repeat内,但没有成功。我有数据:
**[{"_id":"52fb84fac6b93c152d8b4569","post_id":"52fb84fac6b93c152d8b4567","user_id":"52df9ab5c6b93c8e2a8b4567","type":"hoot",},{"_id":"52fb798cc6b93c74298b4568","post_id":"52fb798cc6b93c74298b4567","type":"story",{"_id":"52fb7977c6b93c5c2c8b456b","post_id":"52fb7977c6b93c5c2c8b456a","type":"article",** $ scope.comments =上面提到的数据 <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> 我如何在Angular中实现这个东西?
尝试用引号’:’包围字符串(hoot,story,article)
<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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |