Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html AngularJS-将变量插入脚本属性_Html_Angularjs - Fatal编程技术网

Html AngularJS-将变量插入脚本属性

Html AngularJS-将变量插入脚本属性,html,angularjs,Html,Angularjs,我有一个变量“widgetDataHash”(字符串)和脚本标记,如下所示: <script type="text/javascript" id="widget" data-hash="{{widgetDataHash}}" src="www.widgetsrc.com"> </script> 我想像这样将widgetDataHash的值插入到data hash属性中。但是当它运行时,它只显示一个普通文本{{widgetDataHash}

我有一个变量“widgetDataHash”(字符串)和脚本标记,如下所示:

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

我想像这样将
widgetDataHash
的值插入到
data hash
属性中。但是当它运行时,它只显示一个普通文本
{{widgetDataHash}
,而不是
widgetDataHash
的值


有什么解决方案吗?

我认为对于Angular2+和Angularjs,应该这样写
[attr.data hash]=“widgetDataHash”
ng attr data hash=“widgetDataHash”

我应该提到,我在Nobita回答的链接中找到了这个解决方案(对于Angularjs解决方案)。有关更多信息,请检查答案

请提供angular 2+的答案,谢谢通知。我改变了我的答案。除了脚本,它只适用于普通的标记html。你还有别的想法吗?