Posts

Showing posts from September, 2013

AngularJS how to cast html element

this will usually be used by SharePoint Developers since in angular u have the ngBindHtml.

but in SP u usually get a fields as a complete html like LinkFields or ImageFields and u don't want to put then under a container, like the bindHtml force u, but to put it strait in a template.

so I did this:
<ling-repeat="item in service.data">
<imgcast-me="Image"src="../img/PrePic.JPG"/>
<ahref="#"class="linkArrow"cast-me="Link2"></a>
</li>

and my castMe directive:
Module.directive("castMe", function ($compile, $timeout) {
   return {
     link: function (scope, element, attrs) {
var newElem = angular.element(scope.item[attrs.castMe]);
       $compile(newElem)(scope);
if (element.attr('class') !== '')
         newElem.attr('class', element.attr('class'));
       element.replaceWith(newElem);
     }
  };
});

the point is t…