当特定字段不是模型的字段时,如何在控制器中检索表单值?
<form name="userForm" ng-submit="updateUser()">
//fields of model
<input type="text" name="firstname" ng-model="user.first_name" required/>
//not bound to model
<input type="password" name="password"/>
<input type="password" name="password_confirmation"/>
</form>
在控制器中:
console.log($scope.password);
返回未定义。是否可以在不修改用户资源的情况下获取密码?
答案 0 :(得分:2)
您只需添加ng-model="password"
,它就会被添加到范围中,但不会添加到$scope.user
:
<input type="password" name="password" ng-model="password" />
<input type="password" name="password_confirmation" ng-model="password_confirmation" />