AngularJS ng-value and ng-model do not work together [duplicate]

隐身守侯 提交于 2019-12-02 11:14:52

You cannot use these directives together

"It can also be used to achieve one-way binding of a given expression to an input element such as an input[text] or a textarea, when that element does not use ngModel."

You should set this value in your controller rather than use ng-value.

The documentation clearly states that ng-value should not be used when doing two-way binding with ng-model.

From the Docs:

ngValue

Binds the given expression to the value of the element.

It can also be used to achieve one-way binding of a given expression to an input element such as an input[text] or a textarea, when that element does not use ngModel.

AngularJS ng-value Directive API Reference

Instead, initialize the value from the controller:

<textarea  ̶n̶g̶-̶v̶a̶l̶u̶e̶=̶"̶m̶a̶i̶n̶.̶r̶e̶c̶o̶r̶d̶.̶b̶a̶s̶i̶c̶_̶i̶n̶f̶o̶.̶a̶p̶p̶l̶i̶c̶a̶t̶i̶o̶n̶_̶l̶e̶t̶t̶e̶r̶"̶
           class="form-control" 
           ng-model="main.record.name" 
           name="name" rows="15" cols="80" style="resize: none">
</textarea>
$scope.main.record.name = $scope.main.record.basic_info.application_letter;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!