Hi I am receiving an HTML response with full angular code embedded in it and I have tried both ng-bind-html and ng-html-compile for rendering. Neither of it works.The HTML elements are getting rendered properly but none of the ng directives are working. Can anyone please help on this issue?
Inside my controller i am assigning the http response data(html) into a rootscope variable ($rootScope.htmlResponse=data).
this is directive for html compile
.directive('ngHtmlCompile', function($compile) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
scope.$watch(attrs.ngHtmlCompile, function(newValue, oldValue) {
element.html(newValue);
$compile(element.contents())(scope);
});
}
};
})
searchResults.html:
<ion-view ng-swipe-left="scanClick()">
<ion-nav-buttons side="left">
<button class="button button-icon button-dark ion-navicon" menu-toggle="left" style="margin-left:-10px;margin-right:-20px" id="lhm_button">
</button>
</ion-nav-buttons>
<ion-nav-title>
Product Detail
</ion-nav-title>
<ion-nav-buttons side="right">
<button class="button button-icon button-dark ion-search" ng-click="searchIconClick()" style="margin-top:4px;background:#8eb4e3;line-height:5px"></button>
</ion-nav-buttons>
<ion-content>
<div>
<p **ng-html-compile="htmlResponse"**></p>
</div>
</ion-content>
</ion-view>
Here is the sample of the http response i am getting:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>TEST</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.1/angular.min.js"> </script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.1/angular-animate.min.js"></script>
</head>
<body ng-app="myapp">
<div ng-controller="myController">
{{name.myname}}
</div>
<script>
var app = angular.module('myapp', []);
app.controller('myController', function ($scope) {
$scope.name={};
$scope.name.myname = "stack";
});
</script>
</body>
</html>
The following result is getting displayed:
{{name.myname}}