Angular.js programmatically setting a form field to dirty

后端 未结 11 2041
孤独总比滥情好
孤独总比滥情好 2020-12-02 10:57

I am programmatically updating some of the fields on my form with a value and I would like to set the field state to $dirty. Doing something like:

11条回答
  •  庸人自扰
    2020-12-02 11:20

    If you have access to the NgModelController (you can only get access to it from a directive) then you can call

    ngModel.$setViewValue("your new view value");
    // or to keep the view value the same and just change it to dirty
    ngModel.$setViewValue(ngModel.$viewValue);
    

提交回复
热议问题