Angularjs expression and Instance code _angularjs

Source: Internet
Author: User


With a look at the basic usage of ANGULARJS, here we'll follow the PDF to learn what the expression is about.



The expression in Angularjs is not exactly the same as in JS.



First, its expression is to be used in {{}}, followed by the concept of an expression in JavaScript, which differs from the following:



1 scopes differ



 The default function in JavaScript so window, but in the Angularjs is different. It uses $scope control to function.



2 to allow undefined values



 In Angularjs, if an undefined expression is used, no error occurs and a null value is returned directly.



3 Filters



 you can use the | pipe command in an expression to add a filter, similar to the UNIX command line.  



4 $ symbol



Methods used to distinguish angular from user-defined methods.



Let's look at a small piece of code:


<!doctype html>
<html ng-app>
  <head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <script src="http://apps.bdimg.com/libs/angular.js/1.2.16/angular.min.js"></script>
  </head>
  <body>
    <div ng-controller="ctl">
      name:<input ng-model="name" type="text">
      <button ng-click="reset()">reset</button>
      <br>
      {{name}}
      <br>
      hello ! {{test}}
      <br>
      filter : {{name | uppercase}}
    </div>
    <script type="text/javascript">
      function ctl($scope){
        var str = "init";
        $scope.name = str;

        $scope.reset = function(){
          $scope.name = str;
        }
      }
    </script>
  </body>
</html>


Reset the contents of the name variable by resetting the Reset method;



In an expression, the undefined test is referenced, but there is no error, and the default display is null;--{{test}



Finally, a filter is used to convert the value of name in an expression to uppercase. --{{name | uppercase}}



Run Result:












The above is the ANGULARJS expression of data collation, follow-up continue to supplement the relevant information, thank you for your support!


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.