控制器中的AngularJs setDirty

时间:2017-12-13 09:07:56

标签: angularjs controller

我正在尝试在单击特定按钮后将某些字段设置为脏。

模板

<div class="col-md-4">                          
    <label class="radio radio--inline">
      <input type="radio" class="radio__control" name="radio_Role"ng-model="Form.RoleCheck" value="1" required> 
      <span class="radio__label">
         Whatever
      </span> 
    </label>
</div>

<button id="gotoPersonendatenVn" ng-click="dirty()" type="button">
        Dirty
</button>

app.js

$scope.dirty = function(){
    $scope.Form.RoleCheck.$setDirty();
}

我尝试过不同的东西,但我总是得到“TypeError:$ scope.Form.RoleCheck is undefined”

1 个答案:

答案 0 :(得分:0)

首先,检查您尝试添加$setDirty的位置,尝试将其添加到ngModel,而不是name="radio_Role"

你的形式在哪里

<form name="Form">

 <input type="radio" class="radio__control" name="radio_Role" ng-model="modelName" value="1" required> 

如果您想将输入设置为脏

$ scope.Form.radio_Role = false;