chaitanay chaitanay - 2 years ago 256
Javascript Question

dynamic metatags in view source page angularjs

hi in my requirement i want to update metatags content through dynamically. content was updated successfuly in INSPECT ELEMENT but i didn't see updated content in view source page. i want to update metatags in view source page also through dynammic. please help me to solve this requirement. please see my code. i find this code in google. i need to update metatags in view source page please

<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; }
$rootScope.metaservice = MetaService;
$rootScope.metaservice.set("Web App","desc","blah blah");});</script><body ng-controller="myCtrl"></body></html>

Answer Source

The view page source is the source downloaded from the server to the browser. What happens in memory doesn't get updated in the source.

It is the source which was created by server and hence your update on local DOM elements does not reflect on the page source. It will be show how it was been fetched from server.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download