This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// IIFE in ES5 | |
(function() { | |
console.log('IIFE ES5'); | |
})() | |
// IIFE in ES6 | |
(() => { | |
console.log('IIFE ES6'); | |
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link rel="stylesheet" href="styles.css"> | |
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
@Component({ | |
selector: 'app-root', | |
template: ` | |
<app-parent></app-parent> | |
<app-unrelated></app-unrelated> | |
`, | |
styles: [] | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class UserComponent implements OnInit { | |
users: User[]; | |
constructor(private userService: UserService) {} | |
ngOnInit() { | |
this.userService.getUsers().subscribe((users: User[]) => this.users = users); | |
} | |
userCreated(user: User) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Abstraction: objects, classes, and variables | |
Encapsulation: private, public, protected | |
Inheritance: new classes share some of the attributes of existing classes (parent, child class, extends) | |
Polymorphism: method overloading, method overriding | |
S: Single Responsibility Principle | |
- A class should have only one job. | |
O: Open-Closed Principle | |
- Software entities (Classes, modules, functions) should be open for extension, not modification. | |
L: Liskov Substitution Principle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const kittens = animals.find(x => x.type === 'cat' && x.ageMonths < 12); | |
const kittens = animals.find(animal => animal.type === 'cat' && animal.ageMonths < 12); | |
const kittens = animals.filter(animal => animal.type === 'cat').filter(cat => cat.ageMonths < 12); | |
const kittens = animals.filter(onlyKittens); | |
const onlyKittens = ({ type, ageMonths }) => type === 'cat' && ageMonths < 12; | |
// When to use map? | |
// .map() when you want to transform elements in an array. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div *ngIf="(user$ | async) as user; else loading"> | |
<user-profile | |
[user]="user"> | |
</user-profile> | |
<user-messages | |
[user]="user"> | |
</user-messages> | |
</div> | |
<ng-template #loading> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ng-container | |
*ngIf="isLoggedIn; then loggedIn; else loggedOut"> | |
</ng-container> | |
<ng-template #loggedIn> | |
<div> | |
Welcome back, friend. | |
</div> | |
</ng-template> | |
<ng-template #loggedOut> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div [ngClass]="{ | |
'is-active': condition, | |
'is-inactive': !condition, | |
'is-focused': condition && anotherCondition, | |
}"> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const ROUTES: Routes = [ | |
{ | |
path: '', | |
canActivate: [CoursesGuard], | |
component: CoursesComponent, | |
}, | |
{ | |
path: ':id', | |
canActivate: [CoursesGuard], | |
component: CourseComponent, |
OlderNewer