I want to display some html on a scene (an image of a man or a woman), depending on the gender of the person logged on my website. The directive ng-bind-html works when I define "imageToLoad" statically. However, it doesn't work if my html to bind is defined by a function.
The console tells me: TypeError: $scope.getHtml is not a function
Here is my simplified code:
HTML:
<div id="img-container" ng-controller="sceneCtrl" ng-bind-html="imgToLoad">
</div>
JS:
.controller('sceneCtrl', function($scope, $http, $sce){
/* This works
** $scope.imgToLoad = $sce.trustAsHtml('<img id="over2" src="imgMale.png"/>');
*/
$scope.imgToLoad=$scope.getHtml();
$scope.getHtml=function(){
var gender='male';
if(gender=='male'){
return $sce.trustAsHtml('<img id="over2" src="imgMale.png"/>');
}
else if(gender=='female'){
return $sce.trustAsHtml('<img id="over2" src="imgFemale.png"/>');
}
return 'error getHtml';
}
})
I simplified the JS with a variable saying the gender, but eventually the gender will be given by the backend, from a database.
According to my research, I may have to use "compile", but I have no idea how this works.
Thanks for your help !