0

I want to use angularJs string interpolation inside Jquery html function

$('#existingScoresForWeek').html("<p>{{1 + 1}}</p>");

The above line of code is not printing Result as 2

<div data-ng-app="myApp"  ng-controller="myCtrl">
<p id="existingScoresForWeek"></p>
<button ng-click="myFunc()">sub</button>

</div>

<script>

var app = angular.module("myApp", ['ngSanitize']);
app.controller("myCtrl", function($scope) {
$scope.myFunc= function(){
    ScoreScreenersSave();
};
function ScoreScreenersSave() {
    $('#existingScoresForWeek').html("<p>{{1 + 1}}</p>");
}

});
</script>

Actual Result: {{1 + 1}} Expected Result : 2

1 Answers1

1

Use $compile to compile your html string. See below:

var app = angular.module("myApp",[]);
app.controller("myCtrl", function($scope, $compile) {
  $scope.myFunc= function(){
     ScoreScreenersSave();
  };
  function ScoreScreenersSave() {
     $('#existingScoresForWeek').html($compile("<p>{{1 + 1}}</p>")($scope));
  }
});

Hope it helps!

Harshad
  • 134
  • 1
  • 6