Angularjs Ng-change instructions and simple examples _angularjs

Source: Internet
Author: User


Angularjs ng-change Instruction



Angularjs instance



Executes the function when the value of the input box changes:


<! DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<script src = "http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"> </ script>
</ head>
<body ng-app = "myApp">
<div ng-controller = "myCtrl">
  <p> Enter some information in the input box: </ p>
  <input type = "text" ng-change = "myFunc ()" ng-model = "myValue" />
  <p> The input box has been modified {{count}} times. </ p>
</ div>

<script>
  angular.module ('myApp', [])
   .controller ('myCtrl', ['$ scope', function ($ scope) {
    $ scope.count = 0;
    $ scope.myFunc = function () {
     $ scope.count ++;
    };
   }]);
</ script>
</ body>
</ html> 


Run Result:



Enter some information in the input box:






The input box has been modified 0 times.



Definitions and usage



The ng-change directive is used to tell angularjs what action needs to be performed when the value of an HTML element changes.



Ng-change instructions need to be used with ng-model instructions.



The Angularjs ng-change instruction instruction does not overwrite the native onchange event, and if the event is triggered, the ng-change expression is executed with the native onchange event.



The Ng-change event is triggered each time a value changes, and it does not need to wait for a completed modification or wait for the action to lose focus.



The Ng-change event is modified only for real changes to the value of the input box, not through JavaScript.



Grammar



<element ng-change= "expression" ></element>



<input>, <select>, and <textarea> element support.



Parameter values





value Description
Expression Executes an expression when the value of the element changes.





The above is the Angularjs ng-change instruction of knowledge collation, follow-up continue to add.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.