ANGULAR2 Component Development-template Syntax (v)

Source: Internet
Author: User

(event)-Listen for events

Adding an event listener to an element in a template is simple, wrap the event name with a pair of parentheses, and bind to an expression:

The above code instance adds the Listener function onclick () to the Click event of the DOM object H1.

Another equivalent writing method is to prefix the event name with on-:

1 on-click= "OnClick ()" >HELLO

For example:

1<!doctype html>234<meta charset= "Utf-8" >5<title>template-bind propery</title>6<script type= "Text/javascript" src= "Lib/[email protected]" ></script>7<script type= "Text/javascript" src= "Lib/angular2.dev.js" ></script>8<script type= "Text/javascript" src= "Lib/system.config.js" ></script>9Ten<body> One<ez-app></ez-app> A      -<script type= "Module" > -Import {Component,view,bootstrap} from "Angular2/angular2"; the  -@Component ({selector: "Ez-app"}) - @View ({ - Template: ' + -<button(click)= "Roulette ()" >ROULETTE</button> +                ` A         }) at class ezapp{ - Constructor () { -                  This. names = ["Jason", "Mary", "Linda", "Lincoln", "Albert", "Jimmy"]; -                  This. Roulette (); -             } -             //Roulette Betting in Roulette () { -                 varIDX = parseint (Math.random () * This. names.length); to                  This. SB = This. Names[idx]; +             } -         } the                  * Bootstrap (Ezapp); $ Panax Notoginseng</script> -</body> the

ANGULAR2 Component Development-template Syntax (v)

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.