长话短说,我已经尝试了十亿种方法将参数作为文本放入字符串中,没有解决方案。我决定使用Document.Write作为HTML来欺骗和打印全局变量...但是,我发现AngularJS中的HTML部分不会让我在部分页面上使用和标记。
示例:
$routeProvider
.when('/score', {templateUrl: 'partials/score.html'})
然后,在score.html上,我无法提出这个陈述。它根本不执行:
<script type="text/javascript">
document.write("This is a test");
//document.write("This is a test"+$rootScope.variable);
</script>
我也尝试过window.document.write,甚至是ngApp.document.write。它似乎根本就没有写。在网络视图中,看起来JS根本没有运行。为什么?怎么样?
编辑:我知道数据绑定。它在属性字符串中不起作用......我不知道为什么。这不起作用:<div addthis-toolbox class="addthis_toolbox addthis_default_style addthis_32x32_style social-width" style="width: 150 px">
<a class="addthis_button_twitter" addthis:title="My score is {{score}}"></a>
</div>
EDIT2:实际上,我认为可能会有一个指令覆盖div类。这是有问题的角度指令:
myApp.directive('addthisToolbox', function() {
return {
restrict: 'A',
transclude: true,
replace: true,
template: '<div ng-transclude></div>',
link: function ($scope, element, attrs) {
// Dynamically init for performance reason
// Safe for multiple calls, only first call will be processed (loaded css/images, popup injected)
// http://support.addthis.com/customer/portal/articles/381263-addthis-client-api#configuration-url
// http://support.addthis.com/customer/portal/articles/381221-optimizing-addthis-performance
addthis.init();
// Ajax load (bind events)
// http://support.addthis.com/customer/portal/articles/381263-addthis-client-api#rendering-js-toolbox
// http://support.addthis.com/customer/portal/questions/548551-help-on-call-back-using-ajax-i-lose-share-buttons
addthis.toolbox($(element).get());
}
}
});
如果数据绑定有影响它的指令,如何将数据绑定传递给属性?