ANGULAR in less than 128 words – TypeScript – Angular Part 8

This article follows the first seven on the subject ANGULAR and deals with the language TypeScript:

Templates and interpolation

Interpolation is the incorporation of expressions into marked text. By default, interpolation uses double braces, 'and 'a' as a delimiter.

<h3>Customer Number: 'numbereroClient'</h3>

Example of a directive with iteration:

<li *ngfor="let client of listeClients">'customer.name'</li>

Services:

The services allow to decouple the component of the call to a service, they are thus reusable.

ng generate customer service
import - Injectable - from '@angular/core';

@Injectable
  providedIn: 'root',
})
export class ClientService

  constructor()

}

The logic is then decoupled from the service which is injectable via the addiction injection.

Addiction injection

Example of injection of CustomerService dependency into a CustomerComponent component

import - Component, OnInit - from '@angular/core';

import 'Hero ' from '.. /hero';
import 'HeroService ' from '.. /hero.service';
import 'MessageService ' from '.. /message.service';

@Component
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  StyleUrls:['./heroes.component.css']
})
export class ClientComponent implements OnInit

...

  getClients(): void
    this.clientService.getClients();
  }
}