Dr_Fresse Dr_Fresse - 21 days ago 6
Javascript Question

add content to uib-tooltip-html

Why does this work just fine:

Controller:

$scope.getHtml = $sce.trustAsHtml("<div>Test</div>");


View:

<div uib-tooltip-html="getHtml">Test</div>


But the following doesn't work at all? ;-(

Controller:

$scope.getHtml = function (){
var textOutput = "<div>Text</div>";
return $sce.trustAsHtml(textOutput);
};


View:

<div uib-tooltip-html="getHtml()">Test</div>


Error message is: angular.min.js:6 Uncaught Error: [$rootScope:infdig]

Answer

In the first case $scope.getHtml ends up to be a string.

In the second case $scope.getHtml ends up to be a function, which returns the same string as the first case.

However if you call your function in the second case, it would work, as it is essentially the same code:

$scope.getHtml = function () {
    var textOutput = "<div>Text</div>";
    return $sce.trustAsHtml(textOutput);        
} ()
Comments