Jho*_*aze 5 html javascript angularjs angularjs-ng-init angular-ngmodel
我有一点问题.我想设置脏一个输入,我的意思是,因为当我自动给出一个值时它会保持在pristine类中,不会改变,也不会保存新值.
如果我编辑它,它可以工作并更改类.我想取消那pristine堂课.如果有人知道请告诉我.
<form class="form-horizontal" ng-repeat="studiant in studiants" name="form" id="form">
<input type="hidden" name="id" value="{{studiant.studiant_id}}" class="form-control" disabled>
<div class="form-group">
<label for="school" class="col-md-2 control-label">School</label>
<div class="col-md-1">
<input type="text" id="school" name="school" class="form-control" ng-init="studiant.school=studiant.studiant_school" ng-model="studiant.school">
</div>
</div>
<div class="form-group">
<label for="name" class="col-md-2 control-label">Student's Name</label>
<div class="col-md-10">
<input type="text" id="name" name="name" class="form-control" ng-init="studiant.name=studiant.studiant_name" ng-model="studiant.name">
</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
和剧本:
document.getElementbyId('name').value = "anything";
Run Code Online (Sandbox Code Playgroud)
或者,如果我做错了,我必须改变value用的ng-model东西,请帮助我.
http://plnkr.co/edit/bVoljJqiK3CLB2xqZ6Zm?p=preview
你可以在那里看到一个有效的例子.
确保为表单和输入设置了名称attr.
HTML示例:
<button id="dirty-button" ng-click="addText(); myForm.myText.$setDirty()">Make Dirty</button>
<hr>
<form name="myForm">
<input name="myText" id="myTextInput" type="text" ng-model="myText" required>
</form>
<br/>
<span ng-show="myForm.myText.$dirty">it's dirty now</span>
Run Code Online (Sandbox Code Playgroud)
一个简单的功能:
$scope.addText = function() {
$scope.myText = "now I'm dirty";
}
Run Code Online (Sandbox Code Playgroud)