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

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

问题描述

[object Object] 自动作为值出现在我表单中的每个文本框中.我可以知道出了什么问题吗?它出现在我在标签中插入属性 name="searchr" 之后.谢谢.

在 search.htm 中:

<块引用>

<input type="search" placeholder="在这里搜索" id="text_search" ng-model="searchr.text" name="text">

在 controller.js 中:

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

解决方案

这将创建一个 FormController 类型的对象,并将其存储到名为 searchr 的作用域中.

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

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

不要为表单使用与用于存储表单模型的名称相同的名称.

[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.

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">

in controller.js:

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

解决方案

<form name="searchr">

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

<input name="text">

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

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

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天全站免登陆