最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Show ng-repeat item only when value to display is not null - Stack Overflow

programmeradmin3浏览0评论

I just stared learning AngularJS few days ago. I have a ng-repeat on an element, but I want to use ng-show with it somehow as well. This is my code now:

<p ng-repeat="(parameter,value) in object">{{parameter}}: {{value}}</p>

Which works well where object is structured as

{"MobilePhone":null,"Email":"[email protected]","HomePhone":null}

I want to show only elements that don't have null as a value. Something like:

 <p ng-repeat="(parameter,value) in object" ng-show={{value}}>{{parameter}}: {{value}}</p>

But I don't see why value would be available there for ng-show already? How can I do an "If" check for value before showing

?

Thanks for any help. If I was unclear, please ask for more info.

I just stared learning AngularJS few days ago. I have a ng-repeat on an element, but I want to use ng-show with it somehow as well. This is my code now:

<p ng-repeat="(parameter,value) in object">{{parameter}}: {{value}}</p>

Which works well where object is structured as

{"MobilePhone":null,"Email":"[email protected]","HomePhone":null}

I want to show only elements that don't have null as a value. Something like:

 <p ng-repeat="(parameter,value) in object" ng-show={{value}}>{{parameter}}: {{value}}</p>

But I don't see why value would be available there for ng-show already? How can I do an "If" check for value before showing

?

Thanks for any help. If I was unclear, please ask for more info.

Share Improve this question asked Jan 31, 2014 at 10:01 trainoasistrainoasis 6,72112 gold badges54 silver badges83 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

This will work, and only if value is a truly value it will be shown:

<p ng-repeat="(parameter,value) in obj" ng-show="value">{{parameter}}: {{value}}</p>

(You can also use ngIf instead)

Example: http://jsfiddle/zqJKH/

发布评论

评论列表(0)

  1. 暂无评论