-1

To be noted: The site that I am talking here is SPA and using angularjs.

Say I have music site. Now there are n number of albums.

  • Hindi
  • English
  • Bhajans

My requirement is if user clicks on Hindi Albums, the title of the page should be set to Hindi, if he clicks on English title should be updated to English and so on.

Plus,how do I change the og tags as well as every albums has social share buttons so I need to update the og tags as well.

If you say that I can set the title while configuring routes,that doesn't works in my scenario.

Scenario

.when('/albums',
{
    templateUrl: 'Angular-Templates/albums.html',
    controller: 'albumsCtrl',
    caseInsensitiveMatch: true,
    title: 'Albums'
})

Now albumsCtrl in turns calls db function and fetches the list of availbles albums. Now user will click on any of the fetched albums and title should be updated to the name of the album,

FYI:- I am NOT using angular.ui, but core angular.

abc
  • 7
  • 5

2 Answers2

2

You could define controller at the level.

<html ng-app="app" ng-controller="titleCtrl">
   <head>
     <title>{{ Page.title() }}</title>
 ...
<a ng-click="page">

You create controller:

angular.controller('$scope', 
    function($scope) {
    var title = 'default';
    $scope.page = function(data) {
        title = data;
    }
});

Inject Page and Call 'Page.setTitle()' from controllers.

Miha2255
  • 61
  • 5
1

In order to update the title of the browser in JavaScript, you should utilize the document.title property.

Example:

in controller

$scope.setTitleHindi = function() {
    document.title = "Hindi";
}

and in your template

<span ng-click="setTitleHindi">Click Me!</span>
CollinD
  • 5,885
  • 2
  • 18
  • 38
  • it seems you are in big hurry to downvote the question.. did you read the question completly.. I need to update the og tags as welll..plus check this link http://stackoverflow.com/questions/413439/how-to-dynamically-change-a-web-pages-title – abc Oct 19 '15 at 15:15
  • If this did not answer your question sufficiently, feel free to downvote and move on. I'm not sure what you mean by `og` tags, so I answered the portion of the question that I felt I had the skills to (and what I assumed was the primary question, since it is the title of the ask). That said, SO is not a code-writing service so you may want to post what you've tried! And one more thing, who said I downvoted your question? – CollinD Oct 19 '15 at 15:18
  • if you didn't understand the question, then why you downvoted the question... og -open graph tags (http://ogp.me/) – abc Oct 19 '15 at 15:19
  • This is getting a bit too chatty for the comments, so I'm going to leave it at this. I did not downvote your question, please stop harassing people that have taken time from their day to help you out. – CollinD Oct 19 '15 at 15:21