Skip to content

Instantly share code, notes, and snippets.

@n1lesh
Created December 22, 2017 21:37
Show Gist options
  • Save n1lesh/738ba437008f4ebdd9871cfd216eed65 to your computer and use it in GitHub Desktop.
Save n1lesh/738ba437008f4ebdd9871cfd216eed65 to your computer and use it in GitHub Desktop.
Adding ld+json structured data to AngularJs app Raw - Rich Card Directive
var app = angular.module('home', []);
app.directive('richcard', ['$sce', '$filter', function ($sce, $filter) {
return {
restrict: 'EA',
link: function (scope, element) {
scope.$watch('ld', function (val) {
var val = $sce.trustAsHtml($filter('json')(val));
element[0].outerHTML = '<script type="application/ld+json">'+ val + '</script>'
});
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment