嗨,在我的要求中,我想通过动态更新元标记内容。内容已在 INSPECT ELEMENT 中成功更新,但我没有在视图源页面中看到更新的内容。我想通过dynammic更新视图源页面中的元标记。请帮我解决这个要求。请看我的代码。我在谷歌找到这个代码。我需要更新视图源页面中的元标记must.how?请
<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 :(得分:0)
视图页面源是从服务器下载到浏览器的源。内存中发生的事情不会在源代码中更新。
这是由服务器创建的源,因此您对本地DOM
元素的更新未反映在页面源上。它将显示它是如何从服务器获取的。