这是我的角度控制器: var myApp = angular.module('myApp',[]);
myApp.controller('GreetingController', ['$scope', '$sce', function ($scope, $sce) {
$scope.greeting = 'my test goes here';
$scope.url = "http://google.com";
var shartthis = "<div addthis-toolbox class='addthis_toolbox addthis_default_style addthis_32x32_style' addthis:url='{{url}}' ng-attr-addthis:title='{{greeting}}'><a class='addthis_button_facebook'></a><a class='addthis_button_twitter'></a> <a class='addthis_button_google_plusone_share'></a><a class='addthis_button_compact'></a><a class='addthis_counter addthis_bubble_style'></a> <script type='text/javascript'>var addthis_config = {'data_track_clickback': false, 'data_track_addressbar': false ,};</script></div>";
$scope.shartthishtml = $sce.trustAsHtml(shartthis);
} ]);
这是我的HTML页面:
<body ng-controller="GreetingController" ng-model="greeting">
<div ng-model="greeting">
{{greeting}}
</div>
<div ng-bind-html="shartthishtml"></div>
Sharethis按钮正在显示,但在分享内容时,它会显示Angular语法而不是其值。
没有任何控制台错误
答案 0 :(得分:1)
myApp.controller('GreetingController', ['$scope', '$sce', function ($scope, $sce) {
$scope.greeting = 'my test goes here';
$scope.url = "http://google.com";
var shartthis = "<div addthis-toolbox class='addthis_toolbox addthis_default_style addthis_32x32_style' addthis:url='{{url}}' ng-attr-addthis:title='{{greeting}}'><a class='addthis_button_facebook'></a><a class='addthis_button_twitter'></a> <a class='addthis_button_google_plusone_share'></a><a class='addthis_button_compact'></a><a class='addthis_counter addthis_bubble_style'></a> <script type='text/javascript'>var addthis_config = {'data_track_clickback': false, 'data_track_addressbar': false ,};</script></div>";
$scope.shartthishtml = $sce.trustAsHtml(shartthis);
} ]);
<body ng-controller="GreetingController">
<div>{{greeting}}</div>
<div ng-bind-html="shartthishtml"></div>
</body>