Stable Function
Class Export
export Class(clsDef: ClassDefinition) : Type<any>
Provides a way for expressing ES6 classes with parameter annotations in ES5.
Basic Example
1 2 3 4 5 6 7 8 9 | var Greeter = ng.Class({ constructor: function (name) { this .name = name; }, greet: function () { alert( 'Hello ' + this .name + '!' ); } }); |
is equivalent to ES6:
1 2 3 4 5 6 7 8 9 | class Greeter { constructor(name) { this .name = name; } greet() { alert( 'Hello ' + this .name + '!' ); } } |
or equivalent to ES5:
1 2 3 4 5 6 7 | var Greeter = function (name) { this .name = name; } Greeter.prototype.greet = function () { alert( 'Hello ' + this .name + '!' ); } |
Example with parameter annotations
1 2 3 4 5 | var MyService = ng.Class({ constructor: [String, [ new Query(), QueryList], function (name, queryList) { ... }] }); |
is equivalent to ES6:
1 2 3 4 5 | class MyService { constructor(name: string, @Query() queryList: QueryList) { ... } } |
Example with inheritance
1 2 3 4 5 6 7 8 9 10 11 12 13 | var Shape = ng.Class({ constructor: (color) { this .color = color; } }); var Square = ng.Class({ extends: Shape, constructor: function (color, size) { Shape.call( this , color); this .size = size; } }); |
exported from @angular/core/index defined in @angular/core/src/util/decorators.ts
Please login to continue.