javascriptangularjsmetaangularjs-bindings

Head tags filled up dynamically with Angular


I would like to know if it's possible to change the values of some HEAD tags dynamically with Angular. An example would be this transformation:

<meta name="theme-color" content="#2F7DCA">

to:

<meta name="theme-color" content="{{ color }}">

This is the theory but I would like to know if someone has tried it and it works, or if this is not the way, how to do it. I am not able to test it right now but I need to know it before starting to code. If it's possible to do it, I would appreciate some examples of how to manipulate other HEAD tags.


Solution

  • You can do this by using the ng-bind attribute (the curly braces may break the code you use to apply the color when the page first loads).
    Have a look at this post: How to dynamically change header based on AngularJS partial view?
    They use it for the title but you can use this for meta tags as well.