3

次のようなhtmlテンプレートがあります。

$scope.template = '<span class="pointer"><i class="icon-refresh pointer" ng-click="refresh()"></i></span>';

を使用してこのテンプレートをバインドしたいのですがng-bind-html、使用しようとしましng-bind-html-unsafeたが、残念ながらクリックアクションなしでhtml文字列をそのままバインドします。

<span ng-bind-html="template"></span>
<span ng-bind-html-unsafe="template"></span>

同様の問題について読んだところ、 のng-click後にロードされると書かれていng-bindたので、この問題を解決する方法を教えてもらえますか?

4

2 に答える 2

2

おそらく、コントローラー内でテンプレートをコンパイルする必要がありますか?

angular.controller('ABCDCtrl', function($scope, $compile){
    var templateHTML = '<span class="pointer"><i class="icon-refresh pointer" ng-click="refresh()"></i></span>';
    $scope.template = $compile(templateHTML)($scope);
});
于 2014-05-27T13:54:52.983 に答える