【发布时间】:2015-06-17 16:26:23
【问题描述】:
我在指令 html 模板中有这个小部件代码。
<script type="text/javascript">
_hcwp = window._hcwp || [];
_hcwp.push({widget:"Stream", widget_id:10862, xid:{{_id}});
(function() {
if("HC_LOAD_INIT" in window)return;
HC_LOAD_INIT = true;
var lang = (navigator.language || navigator.systemLanguage || navigator.userLanguage || "en").substr(0, 2).toLowerCase();
var hcc = document.createElement("script"); hcc.type = "text/javascript"; hcc.async = true;
hcc.src = ("https:" == document.location.protocol ? "https" : "http")+"://w.hypercomments.com/widget/hc/10862/"+lang+"/widget.js";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hcc, s.nextSibling);
})();
在这个模板里面有一个变量 {{_id}}。
但是当角度渲染这个模板时,变量不会在模板内发送。
在某些时候必须在 Temple 内发送一个变量进行渲染?
我的指令:
app.directive('hyperComments', function($timeout) {
return {
restrict: 'E',
templateUrl: './templates/hc.html',
replace: true,
scope: {
xid: '='
},
link: function(scope, element, attrs) {
console.log('hello!');
$timeout(function() {
_hcwp = window._hcwp || [];
_hcwp[0]= { widget:"Stream", widget_id: 28172, xid: 31241123};
// HC.widget("Stream", _hcwp);
(function() {
// if("HC_LOAD_INIT" in window)return;
// var HC_LOAD_INIT = true;
console.log('in');
var lang = (navigator.language || navigator.systemLanguage || navigator.userLanguage || "en").substr(0, 2).toLowerCase();
var hcc = document.createElement("script"); hcc.type = "text/javascript"; hcc.async = true;
hcc.src = ("https:" == document.location.protocol ? "https" : "http")+"://w.hypercomments.com/widget/hc/9345/"+lang+"/widget.js";
var s = document.getElementsByTagName("script")[0];
console.log(s);
s.parentNode.insertBefore(hcc, s.nextSibling);
})();
}, 10000);
}
};
});
模板:
由 HyperComments 提供支持的 cmets
【问题讨论】:
-
你能提供你的模板和指令的完整代码吗?
-
@AvraamMavridis 我证明了完整的代码。
标签: javascript angularjs directive