consdata.com
Technical blog Business blog HR department
PL
angular

Czy wiesz, że w Angular 17 została wprowadzona alternatywa dla *ngIf?

author Dorian Mejer
1 November 2024

W Angular 17 pojawiło się built-it control flow, które zostało ustabilizowane w wersji 18. Są to zamienniki dyrektyw *ngIf, *ngFor, *ngSwitch.

@if jest odpowiednikiem *ngIf. Przykładowe wykorzystanie:

// *ngIf - if-else
<div *ngIf="a > b; then aGreaterBlock else aLessOrEqualBlock"></div>
<ng-template #aGreaterBlock>A jest większe niż B</ng-template>
<ng-template #aLessOrEqualBlock>A jest mniejsze lub równe B</ng-template>
 
// @if - if, else if, else
@if (a > b) {
  A jest większe niż B
} @else if (a < b){
  A jest mniejsze niż B
} @else {
  A jest równe B
}

@if można używać również z async pipe. Przykład wykorzystania:

// *ngIf - async pipe
<ng-container *ngIf="vm$ | async as viewModel">
  
</ng-container>
 
// @if - async pipe
@if (vm$ | async; as viewModel) {
  
}

@if poprawia czytelność szablonów, oddziela logikę od tagów html oraz oferuje klauzulę @else, która będzie wykonana, jeśli zdefiniowany warunek nie zostanie spełniony.

Dokumentacja

  • https://angular.dev/guide/templates/control-flow
  • https://angular.dev/api/common/NgIf
Newest posts

  • Reliable event delivery in Apache Kafka based on retry and DLQ
  • Event Tracking - finding a needle in a haystack
  • Kouncil - a modern Kafka frontend
Join us

  • SENIOR FULLSTACK DEVELOPER (JAVA + ANGULAR) Poznań (hybrydowo) lub zdalnie UoP 14 900 - 20 590 PLN brutto
    B2B 19 680 - 27 220 PLN netto
  • REGULAR FULLSTACK DEVELOPER (JAVA + ANGULAR) Poznań (hybrydowo) lub zdalnie UoP 11 300 - 15 900 PLN brutto
    B2B 14 950 - 21 000 PLN netto
  • ZOBACZ WSZYSTKIE OGŁOSZENIA

technical

newsletter

Sign up

Podobne wpisy

post-image
kouncil

Reliable event delivery in Apache Kafka based on retry and DLQ

Why is there no DLQ in Kafka? Most popular queueing systems such as RabbitMQ or ActiveMQ have built-in systems responsible for reliable message delivery. So why doesn't Kafka offer one?...

author
Jacek Grobelny 13 Sep 2021
post-image
kouncil

Event Tracking - finding a needle in a haystack

Event tracking allows for tracking and visualising the path of a given event or process through Kafka topics.

author
Marcin Mergo 8 Sep 2021
post-image
kouncil

Kouncil - a modern Kafka frontend

Kouncil is a modern Kafka frontend equipped with features essential for developers.

author
Jacek Grobelny 30 Aug 2021
Join us

  • SENIOR FULLSTACK DEVELOPER (JAVA + ANGULAR) Poznań (hybrydowo) lub zdalnie UoP 14 900 - 20 590 PLN brutto
    B2B 19 680 - 27 220 PLN netto
  • REGULAR FULLSTACK DEVELOPER (JAVA + ANGULAR) Poznań (hybrydowo) lub zdalnie UoP 11 300 - 15 900 PLN brutto
    B2B 14 950 - 21 000 PLN netto
  • ZOBACZ WSZYSTKIE OGŁOSZENIA

Sign up for a

technical

newsletter

consdata.com
  • Contact

    • sales@consdata.com
    • +48 61 41 51 000

  • Office

    • K9Office
      Krysiewicza 9/14
      61-825 Poznań
      Polska

  • Solutions

    • Eximee
    • Kouncil
  • Blog Join us
Copyright © 2024 Consdata. All rights reserved. Privacy Policy & Cookies
Chcemy używać plików cookie oraz skryptów podmiotów trzecich do polepszania funkcjonowania tej strony Zgadzam się