json2021 json2021 - 4 months ago 8
AngularJS Question

Why does angular keep showing false when input is touched?

I am new to angular. I have set up the following code to see if an input field has been touched. However when i type on the input field. It doesn't change. Just keeps showing false.

Not sure what I am doing wrong here. Any help would be really appreciated it.

<div ng-app='myApp' ng-form name="myForm">

<input type='text' name='address' ng-model="address" id='address'>

<h1> {{myForm.address.$touched}}</h1>


</div>



<script>

var app = angular.module("myApp",[]);

</script>

Ven Ven
Answer

$touched in AngularJS jargon doesn't mean "was the value changed". That's $dirty's role.

$touched in AngularJS means that the field was blurred (that is, the field isn't selected anymore).

See it in action at plnkr.co.

Comments