2016-05-28 18 views
0

嗨,在我的要求中,我想通過動態更新元標記內容。內容已成功更新INSPECT ELEMENT但我在視圖源頁面中未看到更新的內容。我想通過動態更新視圖源頁面中的元標記。請幫我解決這個要求。請看我的代碼。我在谷歌找到這個代碼。我需要更新視圖源頁面中的元標記must.how?請查看源頁面中的動態元標記angularjs

<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> 

回答

0

查看頁面源代碼是從服務器下載到瀏覽器的源代碼。內存中發生的事情不會在源代碼中更新。

它是創建由服務器,因此您的更新上本地DOM元素在頁面源並不反映源。它將顯示它是如何從服務器獲取的。

+0

對不起,但現在又陷入了一個不同的問題,它完全沒有主題.. :)爲什麼你想更新元標記?你也可以請解釋_if查看源代碼頁未更新如何谷歌採取我的網站metatags內容的搜索purpose_? –

+0

離開那個。感謝您的幫助 – chaitanay

+0

如果這有助於你,那麼你可以** upvote **和**接受答案** ..快樂編碼.. –