I was performing a demo of angularjs example at Jsfiddle. I am simply creating a angularjs directive, which will display a div with background-color red, with static text containing data-bindings as template.
var objApp = angular.module("myApp", []);
objApp.controller("myAppController",
function($scope) {
$scope.name2="temp";
});
objApp.directive("myAppDirective",
function(){
return {
template : "<div style='background-color:red'>"+
"Hello {{name}}"+
"<div ng-transclude></div>"+
"</div>",
scope : true,
transclude : true,
controller : function($scope) {
$scope.name = "tempController";
},
compile : function(tElem, attrs, transcludeFn) {
return function(scope, iElem, attrs, transcludeFn) {
console.log(iElem.html());
//iElem.html("<div ng-show='false'>" +
// iElem.html() +
// "</div>");
}
}
});
When following line is commented, every binding works fine.
iElem.html("<div ng-show='false'>" + iElem.html() + "</div>")
But as soon as comment is removed, binding gets broken. Why is it happening ? Does I have to use $compile on new html, which I am setting on iElem ? Does it was already compiled, when this line was commented ? I have looked for answers, but none of them helped me out.