Zabs
Zabs

Reputation: 14142

'object Object' variable displayed on a form input field

In my AngularJS template I have the following login input field section. It is currently autopopulating the input field with rather than the email address address, it is showing up as in the email field (rather than [email protected] etc..)

[object Object]

my template/view

<input ng-model="form.email" type="email" name="email" placeholder="Email" autocomplete="off">

The ng-model using the variable form.email (although I cannot see where exactly that is coming from yet) - what could be wrong?

Upvotes: 2

Views: 4552

Answers (1)

Roh&#236;t J&#237;ndal
Roh&#236;t J&#237;ndal

Reputation: 27202

Make sure that form.email should be a string not an object.

Working demo :

var app = angular.module('myApp',[]);

app.controller('MyCtrl',function($scope) {
    $scope.form = {
        email: "[email protected]"
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
  <input ng-model="form.email" type="email" name="email" placeholder="Email" autocomplete="off">
</div>

Upvotes: 2

Related Questions