angular.module and jqLite
are killed as well
// Annotation / decorators section
@Component({
selector: 'my-app'
})
@View({
template: '<h1>Hello {{ name }}</h1>'
})
// Component controller
class MyAppComponent {
name: string;
constructor() {
this.name = 'Alice';
}
}
<todo-cmp [model]="todoItem"></todo-cmp>
<todo-cmp (complete)="onComplete()"></todo-cmp>
@Component({
selector: 'todo-cmp',
events: ['complete']
})
class TodoCmp {
constructor() {
this.complete = new EventEmitter();
// EventEmitter is an implementation of both
// the observable and observer interfaces
}
onComplete() {
this.complete.next(); // this fires an event
}
}
<input [ng-model]="todo.text" (ng-model)="todo.text=$event"></input>
<input [(ng-model)]="todo.text"></input>
@Directive({
selector: '[ng-model]',
properties: ['ngModel'],
events: ['ngModelChanged: ngModel'],
host: {
"[value]": 'ngModel',
"(input)": "ngModelChanged.next($event.target.value)"
}
})
class NgModelDirective {
ngModel:any; // stored value
ngModelChanged:EventEmitter; // an event emitter
}
<todo-cmp *ng-for="#item of todos; #i=index" [model]="item" [index]="i"></todo-cmp>
<todo-cmp template="ng-for #item of items; #i=index" [model]="item" [index]="i"></todo-cmp>
<template ng-for #item="$implicit" [ng-for-of]="items" #i="index">
<todo-cmp [model]="item" [index]="i"></todo-cmp>
</template>
import { Component, View } from 'angular2/angular2';
@Component({
selector: 'my-app'
})
@View({
template: '<h1>Hello world</h1>'
})
class MyAppComponent {
constructor() {
}
}
var MyAppComponent = (function () {
function MyAppComponent () {}
MyAppComponent.annotations = [
new Component({...}),
new View({...})
];
return MyAppComponent;
})();
// A simple decorator
@annotation
class MyClass { }
function annotation(target) {
// Add a property on target
target.annotated = true;
}
@Component({changeDetection:ON_PUSH})
class ImmutableTodoCmp {
todo:Todo;
}
type ObservableTodo = Observable<Todo>;
type ObservableTodos = Observable<Array<ObservableTodo>>;
angular
.module('app', [])
.controller('MyController', ['$scope',
function ($scope) {
// some methods
$scope.doSomething = function() { ... }
}
]);
<div ng-controller="MyController">
...
<button ng-click="doSomething()">Do It</button>
</div>
angular
.module('app', [])
.controller('MyController', ['$scope',
function ($scope) {
var vm = this;
// some methods
vm.doSomething = function() { ... }
}
]);
<div ng-controller="MyController as ctrl">
...
<button ng-click="ctrl.doSomething()">Do It</button>
</div>
angular
.module('app', [])
.controller('MyController', MyController);
MyController.$inject = ['$scope'];
function MyController($scope) {
var vm = this;
// some methods
vm.doSomething = function() { ... }
}
<div ng-controller="MyController as ctrl">
...
<button ng-click="ctrl.doSomething()">Do It</button>
</div>
import MyController from './my-controller.js'
angular
.module('app', [])
.controller('MyController', MyController);
class MyController {
constructor($scope) {
...
}
doSomething () { ... }
}
MyController.$inject = ['$scope'];
export default MyController;
@Component({
selector: 'todo-list',
properties: ['list']
})
@View({
templateUrl: 'src/components/todo-list.template.html',
directives: [NgFor, NgIf, NgModel, TodoItem]
})
class TodoList {
constructor(store){
this.store = store;
}
...
clearCompleted() {
this.store.clearCompletedItems();
}
}
TodoList.parameters = [[TodoStore]];
export default TodoList
<video-player #player></video-player>
<video-player var-player></video-player>
<button (click)="player.pause()">Pause</button>