在角度js中是否有任何方法或标记/指令可以在不使用ngClick和ngSubmit的情况下发送数据。
因为在这两种方法中我们必须明确提到函数名称。出于安全考虑,我想避免这种情况吗?
这是我的代码:
<form name="userForm" novalidate>
<div class="col-md-2"></div>
<div class="col-md-8">
<h2 class="title-text">Get Quote</h2>
<div class="row"> </div>
<div class="form-group" ng-class="{ 'has-error' : userForm.name.$invalid && !userForm.name.$pristine }">
<label>Name:</label>
<input type="text" name="name" class="form-control" ng-model="formData.name" required>
<p ng-show="userForm.name.$invalid && !userForm.name.$pristine" class="help-block">name is required.</p>
</div>
<div class="form-group" ng-class="{ 'has-error' : userForm.email.$invalid && !userForm.email.$pristine }">
<label>Email</label>
<input type="email" name="email" class="form-control" ng-model="formData.email">
<p ng-show="userForm.email.$invalid && !userForm.email.$pristine" class="help-block">Enter a valid email.</p>
</div>
<div class="form-group" ng-class="{ 'has-error' : userForm.subject.$invalid && !userForm.subject.$pristine }">
<label>subject:</label>
<input type="text" name="subject" class="form-control" ng-model="formData.subject" ng-minlength="3" ng-maxlength="15">
<p ng-show="userForm.subject.$error.minlength" class="help-block">subject is too short.</p>
<p ng-show="userForm.subject.$error.maxlength" class="help-block">subject is too long.</p>
</div>
<div class="form-group" ng-class="{ 'has-error' : userForm.description.$invalid && !userForm.description.$pristine }">
<label>Description:</label>
<input type="text" name="description" class="form-control" ng-model="formData.description" ng-minlength="3" ng-maxlength="200">
<p ng-show="userForm.description.$error.minlength" class="help-block">description is too short.</p>
<p ng-show="userForm.description.$error.maxlength" class="help-block">description is too long.</p>
</div>
<button class="btn btn-primary btn-lg" id="btn-get-requirement" ng-disabled="userForm.$invalid">Get Quote</button>
</div>
<div class="col-md-2"></div>
</form>
我可以使用id属性在angularjs中提交表单数据吗?或者有任何方法??
答案 0 :(得分:0)
您可以使用$ watch函数获取值,而无需在控制器中提交表单