[[object Object]] appear on textbox in angularjs [closed]

烈酒焚心 提交于 2019-12-13 10:00:50

问题


[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) { }

回答1:


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



来源:https://stackoverflow.com/questions/29719806/object-object-appear-on-textbox-in-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!