Home > Software design >  Is it possible to add img title attribute as dynamically in angularjs?
Is it possible to add img title attribute as dynamically in angularjs?

Time:08-27

I want to add the title attribute as dynamically , or title attribute as same as image url Code is as below.. Is it possible?

<img ng-src="{{ bundle.display_based_order.1.url }}"  alt="bundle" title="bundle"/>

CodePudding user response:

I'm afraid the wording of your question isn't quite clear to me, but if you want to have a dynamically rendered title attribute on an element, just use the {{ }} syntax to bind it to some property in your $scope.

<img src="http://www.gravatar.com/avatar/{{imgHash}}" title="{{imgTitle}}" />

CodePudding user response:

You can use a nullish coalescing operator, like title="{{bundle.display_based_order.1.title ?? bundle.display_based_order.1.url}}" - which basicallys says use the .title data point if available, otherwise use the .url

<img ng-src="{{ bundle.display_based_order.1.url }}"  alt="bundle" title="{{bundle.display_based_order.1.title ?? bundle.display_based_order.1.url}}"/>
  • Related