`<input type=“email”` ng-change is only working for backspace and first entry


`<input type=“email”` ng-change is only working for backspace and first entry


<input type="email" ng-keypress="testFunc()" ng-model="text"
id="femail" class="form-control margin" name="femail"
placeholder="Email*"/>
<p style="color: red;">The input field has changed {{count}} times.</p>



JS


$scope.count = 0;
$scope.testFunc = function() {
$scope.count++;
};



HTML


<input type="email" ng-change="testFunc()" ng-model="text"
id="femail" class="form-control margin" name="femail"
placeholder="Email*"/>
<p style="color: red;">The input field has changed {{count}} times.</p>



JS


$scope.count = 0;
$scope.testFunc = function() {
$scope.count++;
};



If I input : "abc". Result should be : 3 but I'm getting : 0 if i delete using backspack I'm getting: 1 I should get count++ on each input which i'm not getting. I'm trying this example:



https://w3schools.com/angular/tryit.asp?filename=try_ng_ng-change



in my code. Thank you





<input type="email" ng-keypress="testFunc()" ng-model="text" id="femail" class="form-control margin" name="femail" placeholder="Email*"/> <p style="color: red;">The input field has changed {{count}} times.</p> JS $scope.count = 0; $scope.testFunc = function() { $scope.count++; };
– rahim.nagori
Jun 30 at 8:24






Please add some more description as well as JS and HTML code for better understanding. Please elaborate your question as well.
– Ravi Maniyar
Jun 30 at 8:24





I'm new to stack so unable to post things properly. Anyway I'll try: I'm applying ng-change="testFunc" in JS but the counter is not working on any change/input it is working only for backspace button.
– rahim.nagori
Jun 30 at 8:26






HTML <input type="email" ng-change="testFunc()" ng-model="text" id="femail" class="form-control margin" name="femail" placeholder="Email*"/> <p style="color: red;">The input field has changed {{count}} times.</p> JS $scope.count = 0; $scope.testFunc = function() { $scope.count++; }; If I input : "abc". Result should be : 3 but I'm getting : 0 if i delete using backspack I'm getting: 1 I should get count++ on each input which i'm not getting. I'm trying this example: w3schools.com/angular/tryit.asp?filename=try_ng_ng-change in my code. Thank you
– rahim.nagori
Jun 30 at 8:30




1 Answer
1



I just copy/pasted the example from W3(you provided) to test.txt file and renamed it test.html and run in Firefox. All worked fine. I did not have to edit anything. Try what I did first then you will know if it a typo or anything else. But the code is working correctly.





I got my answer. W3 is having input type="text" but I was using type="email"
– rahim.nagori
2 days ago






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to input without newline? (Python)

C++ thread error: no type named ‘type’ MINGW

Analog for TagView in flutter