0

Currently, the snippet for a dictionary site I'm building looks like this:

.when('/dictionary/:word2lookup', {
            title: 'The MySite dictionary',
            templateUrl : 'pages/dictionary.html',
            controller  : 'dictController'
        })

word2lookup is, as the name suggests, the word user enters in the input box and hits the submit button for a translation. When the translated data is rendered in the div below, the URL is programmed to reflect the word like so (say, the user is looking up the word, cortar):

www.mysite.com/dictionary/cortar

However, regardless of the word being looked up, as long as the user stays on this page, the title remains static, i.e. The PeppyBurro dictionary). Is there any way I could pass on the variable word2lookup to the $routeProvider and get it to render a dynamic title like Translation of cortar | The MySite Dictionary?

I tried 'Translation of :word2lookup | The MySite Dictionary' and it failed. I also tried 'Translation of' + :word2lookup + ' | The MySite Dictionary' with no success.

1

1 Answer 1

2

One solution would be to listen to every route change and respectively setting the document title. But many other options are possible by accessing $route.current.params['word2lookup']

app.run(['$rootScope', '$route', '$location', function($rootScope, $route, $location) {
    $rootScope.$on('$routeChangeSuccess', function() {
        if(0 === $location.path().indexOf('/dictionary/')) {
            document.title = 'Translation of ' + $route.current.params['word2lookup'] + ' | ' + $route.current.title;
    });
}]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.