Modify <title> with Angularjs through a form

Asked

Viewed 337 times

0

I have the following code:

         <!-- define-pageTitle -->
    <div id="shareContent">
        <p class="subtitle-app mt30">Define title page</p>
        <form onsubmit="return false">
            <label>Who can browse this hotel:</label>
            <br>
            <input type="text" id="inputPageTitle" placeholder="Define here the title of the page" class="ng-valid ng-dirty">
        </form>
        <br>
        <input class="btnSubmit" type="submit" value="Save" ng-click="saveTitlePage()" hyatt-focus-invalid-field>
        <hr class="silverLinemt30">

    </div>

I need to take the title value of this Ubmit and change my DOM (title) through the Angularjs.

The idea is that a user changes the value of the title when they want through a form where he customizes.

1 answer

2


Use the ng-model

<title>{{title}}</title>

<!-- define-pageTitle -->
    <div id="shareContent">
        <p class="subtitle-app mt30">{{title}}</p>
        <form onsubmit="return false">
            <label>Who can browse this hotel:</label>
            <br>
            <input type="text" ng-model="title" id="inputPageTitle" placeholder="Define here the title of the page" class="ng-valid ng-dirty">
        </form>
        <br>
        <input class="btnSubmit" type="submit" value="Save" ng-click="saveTitlePage()" hyatt-focus-invalid-field>
        <hr class="silverLinemt30">

    </div>
  • the business is that the ng-model will bring according to what I type. But it would be something in time that the customer clicked on Save. would trade up there.

  • there is ok, I will fix it for you then. 1 min, by chance you are using some controller?

  • Add this to your controller Document.title = $Scope.title; Remember that you need to pass the title value in ng-model. abrs

  • Thanks @Vinicius worked super well :)

  • Nothing, my friend. Abrs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.