TIPS

Get a copy, not access directly,

// for example
export class ... {
	private recipes: Recipe[] = [];

	getRecipes() {
		// get a copy from outside, not access the original recipes
		return this.recipes.slice();
	}
}

👉 Spread operator. (...var)

// ES6's feature (spread operator): tranform "[a, b, c]" to "a, b, c"
// because we cannot .push([]), but we can .push(a,b,c)
this.ingredients.push(...ingredients);
<!-- if we just bind a string -->
<div abcXyz="abc">
<div [abcXyz]="'abc'">
<div [abcXyz]="['abc']">

<!-- if we bind objects -->
<div abcXyz="{}">
// convert from string to number
const id = +this.abc['id']; // just add "+" before it!
// an optional param in a method
abc(required_1, required_2, optional?) { // with "?"
	...
}
// When creating a new service (example.service.ts), you wanna add it in
// app.module.ts in the section "providers"

// You can make a shortcut right in the file example.service.ts
// and no need to give it name in app.module.ts
@Injectable({providedIn: 'root'})
export class .... { }
// inject a service in a component
export class ... {
	constructor(private serviceName: ServiceName) { }
	// then you can use it here!
}

Services & Dependency Injection

Service?

Untitled

Why we need services? If we don't use, just use what we have (binding, emit,...) → more components and they need to communicate to each other → too complicated!

DI & Logging service