How to do for description , which is in Array
in controller
, is rendered to <meta name="description" content="{{metadescription}}">
, which is in index.html, and can appear dynamically in views?
I use $ routeParams; when I put: title: ':pageName'
title
is replaced by the current route, when accessing the page. I would like to do something like metadescription
, by making the description that is inside the Array items
in the controller NatureCtrl
appear in the views.
Controller
angular.module('tareasApp')
.controller('NatureCtrl', function ($scope, $routeParams, $sce, $location, $anchorScroll) {
$scope.pageName = $routeParams.pageName;
$scope.items =[
{
href:'/relaxing-sounds-waves',
img:'waves.jpg',
descricao:'Those Relaxing Sounds of Waves'
},
{
href:'/relaxing-ocean-sounds',
img:'ocean.jpg',
descricao:'Nature Sounds Relaxing Ocean Sounds'
}
];
});
app.js
var myApp = angular.module('tareasApp')
myApp.config(function ($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/:pageName', {
templateUrl: 'views/wizard.html',
title: ':pageName',
metadescription: 'Aqui precisa ir algo que faça a ligação entre a descricao, que está no controller NatureCtrl, a metadescription que está na index.html e seja dinamicamente inserido nas views',
controller: 'NatureCtrl'
})
.otherwise({
redirectTo: '/'
});
});
// Dessa forma consigo obter os títulos das páginas baseado na route e routeParams. Como configurar a $rootScope.metadescription para obter a descrição referente a cada páginas?
myApp.run(['$location', '$rootScope', '$routeParams', function($location, $rootScope, $routeParams) {
$rootScope.$on('$routeChangeSuccess', function (event, current) {
var title = current.$$route.title;
if (title && $routeParams){
for(var PageName in $routeParams) {
title = title.replace(new RegExp(':' + PageName, 'g'), $routeParams[PageName]);
}
}
$rootScope.title = title;
$rootScope.metadescription = current.$$route.metadescription;
});
}]);
Page index.html
<!DOCTYPE html>
<html lang="pt-BR" ng-app="tareasApp">
<head>
<meta charset="utf-8">
<title ng-bind="title"></title>
<meta name="description" content="{{metadescription}}">
<base href="/">
<meta name="fragment" content="!">
</head>
<body>
Conteúdo vai aqui.....
</body>
</html>