[英]How to set default and changeable values for an Angular.js form
我已经建立了一个基本表单,并通过angular.js进行了绑定。 当我没有默认设置时,选择和更改值可以很好地显示和更新。 我似乎无法做的是设置可以更改的默认值。
我有一个用基本值定义的控制器(例如,一组具有默认值的单选按钮):
function Contact($scope) {
$scope.contact =
{
'website' : '.com'
}
};
和我的形式:
<form action="#" method="post" ng-controller="Contact">
<input ng-model="contact.website" value=".com" id="com" type="radio" name="website">
<label class="radio-label" for="com">website.com</label>
<input ng-model="contact.website" value=".fr" id="fr" type="radio" name="website">
<label class="radio-label" for="fr">website.fr</label>
<input ng-model="contact.website" value=".br" id="br" type="radio" name="website">
<label class="radio-label" for="br">website.br</label>
</form>
在设置默认值时起作用。 但是,当我单击其他选项之一时,相应的{{ contact.website }}
不会改变。
我想念什么?
我用您的示例构建了一个jsfiddle ,并且似乎可以正常工作,除非我不理解您的问题
<div ng-app="app" >
<form action="#" method="post" ng-controller="Contact">
<input ng-model="contact.website" value=".com" id="com" type="radio" name="website">
<label class="radio-label" for="com">website.com</label>
<input ng-model="contact.website" value=".fr" id="fr" type="radio" name="website">
<label class="radio-label" for="fr">website.fr</label>
<input ng-model="contact.website" value=".br" id="br" type="radio" name="website">
<label class="radio-label" for="br">website.br</label>
<p>{{contact.website}}</p>
</form>
</div>
看看你是什么意思...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.