javascript 如何使用 AngularJS 在输入框中显示值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25085938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 03:54:56  来源:igfitidea点击:

How to display value in Input box with AngularJS

javascripthtmlangularjsfrontend

提问by Fizzzz

I just started learning AngularJS. I want to implement a page for editing user info by showing the old info in the input field on the page. whenever the user want to update info they can see the old info displayed in the input box and they can change the value which will be stored in ng-model. I used before without ng-model and it works

我刚开始学习 AngularJS。我想通过在页面的输入字段中显示旧信息来实现一个用于编辑用户信息的页面。每当用户想要更新信息时,他们都可以看到输入框中显示的旧信息,并且他们可以更改将存储在 ng-model 中的值。我以前在没有 ng-model 的情况下使用过,它有效

<input type="text" value="{{event_detail.title}}" class="inputbox form-control">

However it doesn't work with data-ng-model

但是它不适用于 data-ng-model

<input type="text" value="event_detail.title" required id="title" name="title" class="inputbox form-control" data-ng-model="eve.title" placeholder="Title">

is there anyway to solve this problem?

有没有办法解决这个问题?

采纳答案by harishr

you dont need value

你不需要价值

<input type="text" ng-model="event_detail.title" class="inputbox form-control">

OR

或者

<input type="text" ng-model="event_detail.title" required name="title" 
     class="inputbox form-control" placeholder="Title">

回答by Dennis Traub

In the first example you use event_detail.title. In the bottom example it is eve.title. Please make sure that the variable you use actually exists. Also, if you use ng-value, you shouldn't use the tag's value attribute.

在第一个示例中,您使用 event_detail.title。在底部示例中,它是 eve.title。请确保您使用的变量确实存在。此外,如果您使用 ng-value,则不应使用标签的 value 属性。