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
// Component file | |
// Where the service is injected | |
import { SelectionModel } from "@angular/cdk/collections"; | |
@Component(...metaData) | |
export class AppComponent implements OnInit { | |
constructor(peopleSelection: PeopleSelectionService) {} | |
ngOnInit(): void { | |
console.log( |
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
// Module file | |
// Injecting the service | |
import { NgModule } from "@angular/core"; | |
import { BrowserModule } from "@angular/platform-browser"; | |
@NgModule({ | |
imports: [BrowserModule], | |
declarations: [AppComponent], | |
// See here |
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
@Injectable() | |
export class MyInjectableService {} | |
// Define the Module | |
// Inject the service | |
import { NgModule } from "@angular/core"; | |
import { BrowserModule } from "@angular/platform-browser"; | |
@NgModule({ | |
imports: [BrowserModule], |
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 { SelectionModel } from "@angular/cdk/collections"; | |
@Component(...metaData) | |
export class SelectionExample { | |
peopleSelection = new SelectionModel<Person>(true /* multiple */); | |
select(person: Person): void { | |
this.peopleSelection.select(person); | |
return; | |
} |
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
// Here is a Person type | |
type Person { | |
name: string; | |
age: number; | |
} | |
// This function accepts a Person object and returns their name (a string) | |
function getName(person: Person): string { | |
return person.name; | |
} | |
// This function takes an arguement array of people and returns their combined age (a number) |
NewerOlder