在views.py
中def demo(request,EID):
instance = Employee.objects.get(EID=EID)
form = Update(instance=instance)
return render(request, 'files/demo.html', {'form': form, })
在Forms.py中
class Update(forms.ModelForm):
Name = forms.CharField(label='Name', max_length=75,
widget=forms.TextInput(attrs={'ng-model': 'Name', 'required': 'true'}))
class Meta:
model = Employess
fields = ('Name',)
在Html中:
<input class="ng-pristine ng-empty ng-invalid ng-invalid-required ng-valid-maxlength ng-touched" id="id_Name" maxlength="75" name="Name" ng-model="Name" required="true" type="text" value="Amit">
但问题是当输入的价值&#34; Amit&#34;没有显示在Design.It显示空白值,当我通过JavaScript从控制台获得值也返回空白值。我怎么能显示这个值?
答案 0 :(得分:0)
ng-model
你不能像这样设置默认值。您需要使用ng-init
。你可以这样做:
// HTML
<div ng-init=init({{ dict_from_django_view }})>
// your form here
</div>
// in angular controller
$scope.init = function(data){
// set form defaults here
}