If you are using views and routing in Angularjs, each routed page must have a controller. This way, you can use the following template to run something at the time the view is loaded completely:
/*Estou assumindo que o módulo do controller já está declarado*/
.controller('MeuController', function ($scope) {
$scope.$on('$viewContentLoaded', function () {
//Alterar meta tags com jQuery
});
});
But the bigger problem is that views only change meta tags if they are loaded, so since Search Engines crawlers do not run Javascript, the changed tags will not be captured by crawlers; physical pages will be required for this, unfortunately.
After reading the text of this link, I realized that Google’s Crawler can read and run javascript, however, this javascript MUST be on the same page. In short, the link made the following tests:
- Use of
document.write()
inside <script></script>
in a single HTML file = Crawler read.
- Use of
document.write()
in an archive .js
external = Crawler not read.
- Use of
innerHTML
inside <script></script>
in a single HTML file = Crawler read.
- Use of
innerHTML
in an archive .js
external = Crawler not read.
- Using tabs with jQuery = Crawler read, and associated all content to just one page.
- Use of tabs with AJAX = Crawler read, but associated each tab to a own page.
Overall, the best idea is to tag <meta>
what you want to be indexed, even if part of what’s in the tags is in the views, and not on the home page itself.
https://prerender.io/ is an opensource solution for Angularjs that serves pre-rendered HTML for search Engines. You might be interested.
– OnoSendai