2016-10-28 40 views
0

如何將一個組件的變量綁定到index.html我想從一個組件傳遞/綁定一個var到一個組件在具體的index.html我想改變Angular 2/typescript綁定文本從組件到index.html

<meta property="og:title" content="" /> 
+1

你不能。你可以像使用JS一樣使用typescript來更新標籤。 –

回答

1

你可以嘗試以下方法:

let ogTitleMeta = document.querySelector('meta[property="og:title"]'); 
ogTitleMeta.content = 'change content here!'; 
+0

var ogTitleMeta = document.querySelector('meta [property =「og:title」]'); ogTitleMeta.setAttribute('content','here new content') – Bas

0

這將做的工作:

var allMetaElements = document.getElementsByTagName('meta'); 
    for (var i=0; i<allMetaElements.length; i++) { 
     if (allMetaElements[i].getAttribute("property") == "og:title") { 
      allMetaElements[i].setAttribute('content', 'change content here!'); 
     } 
    }