This is my first question on Stackoverflow so please excuse any mistakes I make. I'm trying to display in the view, some HTML from a template, which I use in the following directive:
app.directive('picturegallery', function () {
return {
scope: true,
restrict: "E",
templateUrl: '../../Controllers/pictureGallery.html'
}
});
I do this on click by applying .push
, so <picturegallery></picturegallery>
gets added to the $scope.sections
:
app.directive("picgallery", function ($compile) {
return function (scope, element, attrs) {
element.bind("click", function () {
scope.count++;
scope.sections.push({ desc: "<picturegallery></picturegallery>" });
angular.element(document.getElementById('template-id')).append($compile("<picturegallery></picturegallery>")(scope));
});
};
});
I use $sce.parseAsHtml
as shown below and it works, but the HTML still doesn't get translated to the actual HTML pointed by the template, and simply shows up as <picturegallery></picturegallery>
. I would like the actual template pointed to by pictureGallery.html
to show up.
$scope.sections = [
{ desc: '<div>hello</div>' },
{ desc: '$sce.parseAsHtml("<picturegallery></picturegallery>")' }
];
Is there any way I could show up the actual content from the template?
I've already been through a couple of solutions like Angularjs: preview sanitized html on Stackoverflow which suggested the use of $sce.parseAsHtml
and $sce.trustAsHtml
but they don't work for my code.