Check $pristine status of ngModel without using a form

前端 未结 3 1252
攒了一身酷
攒了一身酷 2021-02-13 00:41

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:28

    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).

提交回复
热议问题