Skip to content

Instantly share code, notes, and snippets.

@n1lesh
Last active December 22, 2017 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n1lesh/5b7ad9a334b4b310f51b2cbb420abe26 to your computer and use it in GitHub Desktop.
Save n1lesh/5b7ad9a334b4b310f51b2cbb420abe26 to your computer and use it in GitHub Desktop.
Adding ld+json structured data to AngularJs app
/* visit www.apple.com and look at
the source code to find it.
*/
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@id": "https://www.apple.com/#organization",
"@type": "Organization",
"name": "Apple",
"url": "https://www.apple.com/",
"logo": "https://www.apple.com/ac/structured-data/images/knowledge_graph_logo.png?201703170823",
"contactPoint": [
{
"@type": "ContactPoint",
"telephone": "+1-800-692-7753",
"contactType": "sales",
"areaServed": [ "US" ]
}
],
"sameAs": [
"http://www.wikidata.org/entity/Q312",
"https://www.youtube.com/user/Apple",
"https://www.linkedin.com/company/apple",
"https://www.facebook.com/Apple",
"https://www.twitter.com/Apple"
]
}
</script>
app.controller('homeController', ['$scope', function ($scope) {
$scope.$root.ld = {
"@context": "http://schema.org/",
"@type": "WebSite",
"name": 'My Wonderful Site',
"image": "https://mywonderfulsite.com/logo.png",
"description": 'We have the best content in the world',
"url": 'https://mywonderfulsite.com/'
}
}]);
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>'
});
}
};
}]);
@kartheekaleti
Copy link

checking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment