I am using jquery to append html in DOM. This html contains angular syntax which has controller and its variable binding. But once the html is appended, the variables initialized inside the controller does not populate their values instead it gets printed as {{ greeting }}.
JS:
$("#clickDiv").click(function(){
var htmlStr = "<div ng-app='myapp'>"+
"<div ng-controller='mainController'>"+
"<div>{{ greeting.text }}</div>"+
"<div>{{ val }}</div>"+
"</div>"+
"</div>";
$("#right").html($compile(htmlStr));
});
var app = angular.module("myapp", []);
app.controller('mainController', ['$scope', '$compile', function($scope, $compile) {
$scope.greeting = { text: 'Hello' };
$scope.val = 123;
}]);
In the above code I am getting error - $compile is not defined.
JSFIDDLE: http://jsfiddle.net/ashwyn/7v6t6cqm/