NG

Angular Cheatsheet

Angular syntax - component decorators, template binding, and dependency injection basics.

Components

@Component({ selector, template })

Component decorator

@Input() name: string

Property passed in from a parent

@Output() change = new EventEmitter()

Event emitted to a parent

ngOnInit()

Lifecycle hook - after component init

Template binding

{{ value }}

Interpolation

[property]="value"

Property binding

(event)="handler()"

Event binding

[(ngModel)]="value"

Two-way binding

*ngIf="condition"

Conditionally render

*ngFor="let i of items"

Render a list

Services & DI

@Injectable({ providedIn: "root" })

Mark a class as an injectable service

constructor(private svc: MyService)

Inject a service into a component