13
<title ng-show="pageName">{{ $root.pageName }} - Domain Name</title>

I'm trying to change the page title dynamically, when the page is loading the title preloads {{ $root.pageName }} - Domain Name instead of being - Domain Name then loading $rootScope.pageName when its rendered.

Is there a way to hide {{ $root.pageName }} from being shown on page load till the application picks up the variable?

ngplayground
  • 20,365
  • 36
  • 94
  • 173
  • Have you tried ng-cloak? https://docs.angularjs.org/api/ng/directive/ngCloak – alou Aug 31 '14 at 10:42
  • Possible duplicate: http://stackoverflow.com/questions/12866447/prevent-double-curly-brace-notation-from-displaying-momentarily-before-angular-j – Zags Dec 01 '14 at 21:08

4 Answers4

13

You can do it like this:

<title ng-bind="$root.title + ' - Your site'">Your site</title>

Note that in this case the title is on the $rootScope.

EDIT: Just tested and it looks like the dash keeps showing, however this should prevent it:

<title ng-bind="$root.title ? $root.title + ' - Your site' : 'Your site' }]}">Your site</title>
Jon Snow
  • 3,682
  • 4
  • 30
  • 51
2

you can use ng-cloak directive to hide raw (uncompiled) form data.i think it will help you.

<title ng-cloak>{{ $root.pageName }} - Domain Name</title>

The ngCloak directive is used to prevent the Angular html template from being briefly displayed by the browser in its raw (uncompiled) form while your application is loading.

see this link for detail.

Mukund Kumar
  • 21,413
  • 18
  • 59
  • 79
0

Using ng-show in title doesn't make sense. You could do something like:

<title ng-bind="'MyApp - ' + $root.title">MyApp - Welcome</title>

$routeProvider.when('/product', {templateUrl: '/partials/product.html',  controller: 'ProductCtrl', title: 'Discover our Product'}).when('/about', {templateUrl: '/partials/about.html', controller: 'AboutCtrl', title: 'About US'});

on your run(), add a $rootScope.$on:

$rootScope.$on("$routeChangeSuccess", function(currentRoute, previousRoute){
//Change page title, based on Route information
$rootScope.title = $route.current.title;});

Read the Full source: https://coderwall.com/p/vcfo4q

Bilal Budhani
  • 487
  • 3
  • 13
-3

Yes it is possible.

Do something like this

<title ng-show="pageName">
    <span ng-model="pageName"></span>
    <span> - Domain Name</span>
</title>
Aditya Sethi
  • 10,486
  • 11
  • 26
  • 31
  • -1: `ng-show` generally influences the `display` style of an element (animations aside) and `` shouldn't contain anything other than text according to the [W3C style guide](http://www.w3.org/Provider/Style/TITLE.html). – tavnab Apr 19 '16 at 18:41