[英]angular command in ng-bind-html
I'm trying to use $interpolate
and ng-bind-html
to bind the data of my scope variable to a html string by this answer . 我正在尝试使用
$interpolate
和ng-bind-html
通过此答案将我的范围变量的数据绑定到html字符串。 Now when my scope variable's value is updating the ng-bind-html
result, its not updating. 现在,当我的范围变量的值正在更新
ng-bind-html
结果时,它不会更新。
I don't want to call $interpolate
every time that my scope updates. 我不想每次范围更新时都调用
$interpolate
。
This is my controller code: 这是我的控制器代码:
$scope.TitleFlag= true;
$scope.HtmlContent = "<div>{{TitleFlag}}</div>";
$scope.trustedHtml = $interpolate($scope.HtmlContent)($scope);
$scope.TitleFlagToggle = function(){
$scope.TitleFlag= !$scope.TitleFlag;
};
And this is my view code: 这是我的查看代码:
<div>{{TitleFlag}}</div> <!-- This is update correctly -->
<div ng-bind-html="trustedHtml"></div> <!-- This is not update -->
<button class="button" ng-click="TitleFlagToggle()"></button>
While the TitleFlag is changing we need to interpolate it. 当TitleFlag更改时,我们需要对其进行插值。 So put the $scope.trustedHtml also in click function too.
因此,也将$ scope.trustedHtml也放在click函数中。
$scope.TitleFlag= true;
$scope.HtmlContent = "<div>{{TitleFlag}}</div>";
$scope.trustedHtml = $interpolate($scope.HtmlContent)( $scope);
$scope.TitleFlagToggle = function(){
$scope.TitleFlag= !$scope.TitleFlag;
$scope.trustedHtml = $interpolate($scope.HtmlContent)( $scope);
};
http://plnkr.co/edit/rRjHOY2xSiAZ8EtzviqK?p=preview http://plnkr.co/edit/rRjHOY2xSiAZ8EtzviqK?p=preview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.