[[object Object]]出现在angularjs的文本框中 [英] [[object Object]] appear on textbox in angularjs

查看:386
本文介绍了[[object Object]]出现在angularjs的文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[object Object]会自动显示为表单中每个文本框中的值.我可以知道出什么问题了吗?我在标记中插入属性名称="searchr"后出现.谢谢.

[object Object] is automatically appeared as value in every textbox in my form. May i know what went wrong? It appears after i inserted the attribute name="searchr" in tag. Thanks.

在search.htm中:

in search.htm:

<form ng-submit="search()" ng-controller="formcontrol" name="searchr">
<input type="search" placeholder="Search here" id="text_search" ng-model="searchr.text" name="text">

在controller.js中:

in controller.js:

.controller('SearchCtrl', function($scope, $http) { }

推荐答案

<form name="searchr">

这将创建一个FormController类型的对象,并将其存储在名称为searchr的范围内.

This creates an object of type FormController, and stores it into the scope under the name searchr.

<input name="text">

这将创建一个NgModelController类型的对象,并将其存储在FormController的text属性中.

This creates an object of type NgModelController and stores it in the FormController's text attribute.

<input ng-model="searchr.text">

这告诉angular字段的模型(即必须在字段中显示的文本)为searchr.text,但是由于上述原因,searchr.text是由angular创建的NgModelController对象,这是对象的一部分由angular创建的FormController对象.

This tells angular that the model of the field (i.e. the text that must be displayed in the field) is searchr.text, but due to the above, searchr.textis the NgModelController object created by angular, which is part of the FormController object created by angular.

请不要在表单中使用与存储表单模型所使用的名称相同的名称.

Don't use the same name for the form as the name you use to store the model of the form.

这篇关于[[object Object]]出现在angularjs的文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆