(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> theANGULAR2 Component Development-template Syntax (v)