0

I have a variable "widgetDataHash" (string) and script tag like this:

<script 
   type="text/javascript" 
   id="widget"
   data-hash="{{widgetDataHash}}"
   src="www.widgetsrc.com">
</script>

I want to insert value of widgetDataHash to data-hash attribute like that. But when it run, it just show a normal text {{widgetDataHash}} instead of value of widgetDataHash.

Any solution for this ?

dungmidside
  • 508
  • 7
  • 19

1 Answers1

1

I think you should write like this [attr.data-hash]="widgetDataHash" for angular 2+ and for Angularjs you should write like this ng-attr-data-hash="widgetDataHash" I should mention that I found this solution (for Angularjs solution) in a link Nobita answered that. For more information check Conditionally adding data-attribute in Angular directive template answers

Amin Kamalinia
  • 314
  • 1
  • 4
  • 17