Dynamize title with AngularJS

5

I want to streamline my page% with AngularJS. It's currently static:

<title>Workspace</title>

I would like to know how I can change this name based on what is stored in database . Currently in a place where the client will do the modification ( title ) it looks like this:

<input type="text" ng-model="workspace.titlePage" id="inputPageTitle" placeholder="Define here the title of the page" class="ng-valid ng-dirty">

However, this happens on another page ( input ), there you are able to add to the database and see the information in workspace-admin.html . I would like to get the same information, but on another page ( {{workspace.titlePage}} ).

But when I do index.html , it returns me {{workspace.titlePage}} , since the directive responsible for this value has not been loaded so far.

How can I get this value?

    
asked by anonymous 13.11.2014 / 19:34

1 answer

5

You can create an event in $rootScope on page workspace-admin.html and subscribe to this event on page index.html :

That is, in the controller of workspace-admin.html :

// emissao do evento
$rootscope.$emit("titlechanged@workspaceadmin", titulo);

And then in the controller of index.html :

this.tituloPagina = "PlaceHolder";

// escuta do evento
var eventHolder = $rootScope.$on("titlechanged@workspaceadmin", function(titulo){
    this.tituloPagina = titulo.
});

Finally in index.html :

<title>{{tituloPagina}}</title>
    
13.11.2014 / 20:15