How can I update meta tags in AngularJS? -
i developing application using angularjs. want update meta tags on route change.
how can update meta tags in angularjs can shown in "view source" on page?
here html code -
<!doctype html> <html ng-app="app"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="fragment" content="!" /> <meta name="title" content="test app"> <meta name="description" content="test app"> <meta name="keywords" content="test,app"> <link rel="stylesheet" href="css/jquery-ui-1.10.2.custom.min.css" /> <link rel="stylesheet" href="css/extra.css" /> <script src="js/libs/jquery-1.8.3.min.js"></script> <script src="js/libs/jquery-ui-1.10.2.custom.min.js"></script> <script src="js/libs/angular.min.js"></script> <script src="js/controller.js"></script> <script src="js/routes.js"></script> </head> <body> <div ng-controller="mainctrl" class="main-container" loading> <div class="container-holder"> <div class="container"> <div ng-include src='"elements/header.html"'></div> <div ng-view class="clearfix"></div> </div> </div> <div ng-controller="userctrl" id="test"> <div class="container" class="login-container"> <div id="login-logo"> <img src="images/logo-300.png" alt="" class="login-img"/> <br /> <div ng-view></div> </div> </div> </div> </body> </html>
<html ng-app="app"> <title ng-bind="metaservice.metatitle()">test</title> <meta name="description" content="{{ metaservice.metadescription() }}" /> <meta name="keywords" content="{{ metaservice.metakeywords() }}" /> <script> var app = angular.module('app',[]); app.service('metaservice', function() { var title = 'web app'; var metadescription = ''; var metakeywords = ''; return { set: function(newtitle, newmetadescription, newkeywords) { metakeywords = newkeywords; metadescription = newmetadescription; title = newtitle; }, metatitle: function(){ return title; }, metadescription: function() { return metadescription; }, metakeywords: function() { return metakeywords; } } }); app.controller('myctrl',function($scope,$rootscope,metaservice){ $rootscope.metaservice = metaservice; $rootscope.metaservice.set("web app","desc","blah blah"); }); </script> <body ng-controller="myctrl"></body> </html>
Comments
Post a Comment