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 ?

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

thats for angular 2+
Thank you for notice. I changed my answer.
It just work with normal tag html except script. Do you have any another idea ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.