Dynamic Metadata In AngularJS ngMeta

Welcome to the In infinityknow.com website! You will Step By Step learn web programming, easy and very fun. This website allmost provides you with a complete web programming tutorial presented in an easy-to-follow manner. Each web programming tutorial has all the practical examples with web programming script and screenshots available.For Dynamic Metadata In AngularJS – ngMeta Example

angularjs – Angular Dynamic meta tags in head

AngularJS, the very increasingly popular js framework and JavaScript UI framework, caal to the falls victim to each call this same fate.

<h1>AngularJS App</h1>
<h3>AngularJS King</h3>
<p>This AngularJS web-application is truly All easy to incredible.</p>

ngMeta | Dynamic meta tags for your Angular SPA

Angularjs is a one type of the structure and reliance and very binding on JavaScript, all the url crawlers are left to read each call to templates, not data

READ :  AngularJS and SEO Dynamically Title with Meta Description

<h1>{{ app.name }}</h1>
<h3>{{ app.username }}</h3>
<p>{{ app.description }}</p>

ngMeta – AngularJS Modules, Plugins and Directives Syntax

the desired all the meta tags and some description add the directive we just created as an attribute below examples.

<h1></h1>
<h3></h3>
<p></p>

Dynamic metadata in web pages using AngularJS

In this examples add to dynamically add ngMeta title tag and ngMeta description tag and ngmeta tags add.



    
    
    
    
    
   
    
    <title></title>
    
    
    
	..............
	..............
	///some meta add here

app.js ($routeProvider )

$routeProvider
   .when('/', {
       templateUrl: 'views/contacthome.html',
       controller: 'HomepageCtrl',
       dynemicmetadata: {
           title: 'Happy 2 help You',
           description: 'infinityknow Solution data' }
   })
   .when('/productlist', {
       templateUrl: 'views/productlist.html',
       controller: 'productlistCtrl',
       dynemicmetadata: {
           title: 'Happy 2 help You | productlist',
           description: 'An very impressive to the productlist pages!' }
   })
   

var infinityknow = this;
 
// Set custom and each options or use to all the provided fallback in angularjs (default) options
infinityknow.loadMetadata = function(dynemicmetadata) {
   infinityknow.title = document.title = dynemicmetadata.title || 'Happy 2 help You';
   infinityknow.description = dynemicmetadata.description || 'infinityknow Solution data';
};
 
// Route change events handler, sets all the route's config defined metadata
$rootScope.$on('$routeChangeSuccess', function (event, newRoute) {
   infinityknow.loadMetadata(newRoute.dynemicmetadata);
});

Dynamic Title and Description with AngularJS

return {
  restrict: 'A',
  scope: {
    metaproperty: '@'
  },
  link: function postLink(scope, element, attrs) {
    scope.default = element.attr('content');
    scope.metadata = metadataService;
 
    // Watch for metadata changes and set content
    scope.$watch('metadata', function (newVal, oldVal) {
      setContent(newVal);
    }, true);
 
    // Set the content attribute with new metadataService value or back to the default
    function setContent(metadata) {
      var content = metadata[scope.metaproperty] || scope.default;
      element.attr('content', content);
    }
 
    setContent(scope.metadata);
  }
};

Dynamically set metadata

metadataService.loadMetadata({
  title: 'Happy 2 help You | ' + article.title,
  description: article.description
});

index.html(Angular app with dynamic meta data)

  <title>Happy 2 help You</title>
  
 
  <!-- Open simple Graph Protocol Tags here -->
  
  
  
  
  
 
  <!-- here social media Twitter Card Tags -->
  
  
  
  
  

Dynamically Added Meta Data Indexed By Google Crawlers

nar infinityknow = this;
 
// Set custom and defult options or use to the  provided fallback (default) options
infinityknow.loadMetadata = function(dynemicmetadata) {
  infinityknow.title = document.title = dynemicmetadata.title || 'Happy 2 help You';
  infinityknow.description = dynemicmetadata.description || 'infinityknow Solution data';
  infinityknow.url = dynemicmetadata.url || $location.absUrl();
  infinityknow.image = dynemicmetadata.image || 'infinityknowhelping.com/companylogo.jpg';
  infinityknow.ogpType = dynemicmetadata.ogpType || 'website';
  infinityknow.twitterCard = dynemicmetadata.twitterCard || 'summary_infinityknow_image';
  infinityknow.twitterSite = dynemicmetadata.twitterSite || '@infinityknowhelping';
};
 
// This Route change all the each handler event, sets the route's config data defined metadata and title
$rootScope.$on('$routeChangeSuccess', function (event, newRoute) {
  infinityknow.loadMetadata(newRoute.dynemicmetadata);
});

Example

READ :  C# LinkedList Tutorial with Examples

ngMeta | Dynamic meta tags for your Angular SPA | Dynamically include meta data in angularjs | ngMeta – AngularJS Modules, Plugins and Directives | Dynamically Added Meta Data Indexed By Google Crawlers