Check $pristine status of ngModel without using a form

前端 未结 3 750
野趣味
野趣味 2021-02-13 00:35

Am trying to figure out how to check the state of a ngModel without using a form tag. I don\'t have wrappers is just basic input element with a ngModel.

All the example

3条回答
  •  北海茫月
    2021-02-13 01:40

    If you give the

    element a name attribute, then the will be added to the $scope object as a property.
    Field controller will then be attached to the form property.

    As weird as it could seem, you have to define an enclosing form with a name attribute like so:

    
      
    
    

    and call the property with:

    $scope.myForm.lastname.$dirty
    

    Indeed, ngModelController (field) is attached to ngFormController (form).

提交回复
热议问题