【问题标题】:'object Object' variable displayed on a form input field表单输入字段上显示的“对象对象”变量
【发布时间】:2017-06-12 05:44:58
【问题描述】:

在我的 AngularJS 模板中,我有以下登录输入字段部分。它目前正在自动填充输入字段而不是电子邮件地址,它显示为电子邮件字段(而不是 you@email.com 等)

[object Object]

我的模板/视图

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

使用变量 form.email 的 ng 模型(虽然我还看不到它的确切来源) - 可能有什么问题?

【问题讨论】:

标签: javascript angularjs object


【解决方案1】:

确保form.email 应该是string 而不是object

工作演示:

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

app.controller('MyCtrl',function($scope) {
    $scope.form = {
        email: "you@email.com"
    }
});
<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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-16
    • 1970-01-01
    • 2021-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多