MegaPowerRockstar Posted August 8, 2018 Report Posted August 8, 2018 In html, i have an attribute that i want to be present or deleted based on a flag. ex: html tag: <p class="tip" cust-attr="{{vm.propertyValue}}"><span>{{vm.labelText}}</span></p> flag: vm.display The above should be transformed to, if: vm.display === true then <p class="tip" cust-attr="{{vm.propertyValue}}"><span>{{vm.labelText}}</span></p> vm.display === false then <p class="tip"><span>{{vm.labelText}}</span></p> I tried below option but did not work, because my attribute has - in between <h1 ng-attr-contenteditable="{{isTrue || undefined }}">{{content.title}}</h1> I want to do that at html level, not in angular js. what do you think ? Quote
MegaPowerRockstar Posted August 8, 2018 Author Report Posted August 8, 2018 i can't use ng-if, there are sub-sections in the above tag. let me edit it. Quote
pandit Posted August 8, 2018 Report Posted August 8, 2018 I cannot think of other option. ng-if should be your best bet. Quote
pahelwan Posted August 8, 2018 Report Posted August 8, 2018 49 minutes ago, MegaPowerRockstar said: In html, i have an attribute that i want to be present or deleted based on a flag. ex: html tag: <p class="tip" cust-attr="{{vm.propertyValue}}"><span>{{vm.labelText}}</span></p> flag: vm.display The above should be transformed to, if: vm.display === true then <p class="tip" cust-attr="{{vm.propertyValue}}"><span>{{vm.labelText}}</span></p> vm.display === false then <p class="tip"><span>{{vm.labelText}}</span></p> I tried below option but did not work, because my attribute has - in between <h1 ng-attr-contenteditable="{{isTrue || undefined }}">{{content.title}}</h1> I want to do that at html level, not in angular js. what do you think ? I would use both p tags one with ng-show true and another with no-show false. Quote
stockdazzler Posted August 8, 2018 Report Posted August 8, 2018 try ng-if or ng-show or write your own function. asalu nuvvu emi cheyyali anukuntnnavo naku ardam kale. the above should be transformed to ani oka 2 lines of code rasav. I tried ani cheppi totally different line of code rasav. Quote
Symo Posted August 8, 2018 Report Posted August 8, 2018 (edited) 15 minutes ago, pahelwan said: <h1 ng-attr-contenteditable="{{isTrue || undefined }}">{{content.title}}</h1> Why can't use something like this? <h1 contenteditable="{{isTrue ? value : undefined}}">{{content.title}}</h1> or try this <h1 ng-attr-contenteditable="{{isTrue}}">{{content.title}}</h1> Edited August 8, 2018 by Symo updating answer Quote
subbusahusatya Posted August 8, 2018 Report Posted August 8, 2018 <p class="tip" cust-attr="vm.display === true ? {{vm.propertyValue}} : {{}}"><span>{{vm.labelText}}</span></p> Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.