this question has answer here:
given script below, can found in angular 2 official tutorial, "@" character mean? ecmascript 6 feature?
can elaborate it?
import {component} 'angular2/core'; export class hero { id: number; name: string; } @component({ selector: 'my-app', template:` <h1>{{title}}</h1> <h2>{{hero.name}} details!</h2> <div><label>id: </label>{{hero.id}}</div> <div> <label>name: </label> <input [(ngmodel)]="hero.name" placeholder="name"> </div> ` }) export class appcomponent { public title = 'tour of heroes'; public hero: hero = { id: 1, name: 'windstorm' }; }
it's typescript decorators, check them out here
a class decorator declared before class declaration. class decorator applied constructor of class , can used observe, modify, or replace class definition. class decorator cannot used in declaration file, or in other ambient context (such on declare class).
the expression class decorator called function @ runtime, constructor of decorated class argument.
if class decorator returns value, replace class declaration provided constructor function.
note should chose return new constructor function, must take care maintain original prototype. logic applies decorators @ runtime not you. following example of class decorator (@sealed) applied greeter class:
@sealed class greeter { greeting: string; constructor(message: string) { this.greeting = message; } greet() { return "hello, " + this.greeting; } }
Comments
Post a Comment