Skip to content

Instantly share code, notes, and snippets.

@theninthnode
Created August 9, 2013 08:36
Show Gist options
  • Save theninthnode/6192058 to your computer and use it in GitHub Desktop.
Save theninthnode/6192058 to your computer and use it in GitHub Desktop.
Little snippet to set canonical links in AngularJS. Note. this will only work with crawlers if you implement some sort of interceptor and return fully rendered html/js to the crawler i.e. using PhantomJS
$rootScope.$watch('canonical', function(newVal){
if(newVal != '') {
var link = angular.element('<link>');
link.attr('rel', 'canonical');
link.attr('href', newVal);
angular.element('head').append(link);
}
})
$rootScope.canonical = 'http://google.com';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment