1

I just started using angular js and I was playing with the ng-model directive but I can't figure out what im doing wrong. I want the input email value to show in the h1 tag as I'm typing. pretty much I'm not getting anything show in the h1 tag as I type.

<body ng-app="starter">
    <ion-pane>
        <ion-content style="margin-top: 163px">
            <div ng-controller="loginController">
                <form action="">
                    <div class="row">
                        <div class="col col-50 col-offset-25">
                            <div class="card">
                                <div class="item item-text-wrap">
                                    <div class="list">
                                        <label class="item item-input">
                                            <i class="icon ion-email placeholder       icon"></i><input type="email" placeholder="Email" ng-model="email" />
                                            <h1>{{email}}</h1>
                                        </label>
                                  <label class="item item-input">
                                      <i class="icon ion-locked placeholder-icon"></i><input type="text" placeholder="Password" />
                                  </label>
                                  <br/>
                                  <button class="button button-full button-positive">Clock Me In</button>
                              </div>
                          </div>
                      </div>
                  </div>
              </div>
          </form>
      </div>
  </ion-content>
</ion-pane>
</body>

this is my javascript

var app = angular.module('starter', ['ionic'])

app.controller('loginController', function($scope)
{

})
3
  • you need to pass the value from controller like $scope.email = "[email protected]" then it show in in your page. Commented Jun 5, 2015 at 2:45
  • 4
    Note that if you assigned type="email", the result will only be displayed when the field is valid Commented Jun 5, 2015 at 2:47
  • lol that was the problem the type email. i changed my code to type text and it worked. thanks Commented Jun 5, 2015 at 2:51

1 Answer 1

1

Your changes are not displayed on screen because while you are typing the email it is invalid. Invalid values are reflected to $scope as null, so there is nothing to show.

As suggested in comments, you can change it type="text". Since you removed validation, you'll see the text on both screen and in your $scope, however you'll sacrifice validation.

If you still want to use email validation, and want to see it in screen/$scope you can use ng-model-options as described here.

Using ng-model-options you can allow invalid values to be stored in your $scope.

Try adding ng-model-options="{allowInvalid: true}" to your type="email" input.

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.