How to refactor this logic in the template/view to use a single line if statement (AngularJS 1.x) -
i fixing small issues within our angularjs application - i've come across logic below displays one link.
in pseudocode style..
if (data.serviceid exists in dom) { display link & populate href data.serviceid value } elseif(commentreply.sender.serviceid exists in dom) { display link & populate href commentreply.sender.serviceid value }
the code in template looks follows, how can amend code below cleaner , not duplicating line using form of single line tertiary statement?
<a ng-if="data.serviceid" ng-href="/#/profile/{{data.serviceid}}">view</a> <a ng-if="commentreply.sender.serviceid" ng-href="/#/profile/{{commentreply.sender.serviceid}}">view</a>
for example:
<a data-ng-href="/#/profile/{{data.serviceid && !commentreply.sender.serviceid ? data.serviceid : commentreply.sender.serviceid}}">view</a>
or
<a href="/#/profile/{{data.serviceid && !commentreply.sender.serviceid ? data.serviceid : commentreply.sender.serviceid}}">view</a>
Comments
Post a Comment