An warware: html ngfor tare da fihirisa

Babban matsalar da ke da alaฦ™a da yin amfani da umarnin ngFor tare da fihirisa shine cewa zai iya haifar da sakamako mara tsammani lokacin da aka ฦ™irฦ™iri bayanan akan canje-canje. Wannan saboda ba a sabunta fihirisar ta atomatik lokacin da aka ฦ™ara ko cire abubuwa daga tsararrun, don haka idan an ฦ™ara sabon abu a maฦ™asudin 0, duk sauran abubuwan za a canza maฦ™asudinsu ษ—aya. Wannan na iya haifar da bayyanar da bayanan da ba daidai ba a ra'ayin ku ko halin da ba zato ba tsammani a cikin aikace-aikacenku.

<ul>
  <li *ngFor="let item of items; let i = index">{{i}} - {{item}}</li>
</ul>

1. Wannan layin code yana haifar da jerin marasa tsari.
2. Ana amfani da umarnin *ngFor don yin madauki ta hanyar tsararrun abubuwa da nuna kowane abu a cikin jerin.
3. Ana amfani da kalmar bari don bayyana mabambantan da ake kira "item" wanda ke riฦ™e abu na yanzu a cikin maimaita madauki.
4. Hakanan ana amfani da kalmar bari don bayyana ma'anar canji mai suna "i" wanda ke riฦ™e da index na abin da ke yanzu a cikin maimaita madauki.
5. Wannan layin yana nuna kowane abu a cikin lissafin tare da lambar fihirisa (farawa daga 0).

Menene Angular

Angular tsarin tsarin aikace-aikacen gidan yanar gizo ne na tushen tushen JavaScript na farko wanda Google ke kula da shi da kuma jama'a na mutane da kamfanoni don magance yawancin ฦ™alubalen da aka fuskanta wajen haษ“aka aikace-aikacen shafi guda ษ—aya. Abubuwan JavaScript sun dace da Apache Cordova, tsarin da ake amfani da shi don haษ“aka ฦ™a'idodin wayar hannu. Yana nufin sauฦ™aฦ™e duka haษ“akawa da gwajin irin waษ—annan aikace-aikacen ta hanyar samar da tsari don ฦ™irar abokin ciniki-gani-duba-mai sarrafa (MVC) da ฦ™irar-view-viewmodel (MVVM), tare da abubuwan da aka saba amfani da su a cikin aikace-aikacen Intanet masu wadata.

ngFor element

NgFor umarni ne na tsarin Angular wanda ke ba mu damar yin madauki ta hanyar bayanai da ฦ™irฦ™irar samfuri ga kowane abu a cikin tsari ko abu. Ana amfani da shi don maimaita abin da aka ba HTML ฦ™ayyadadden adadin lokuta. Ana iya amfani da NgFor don nuna bayanai daga tsararru, abu, ko kirtani. Hakanan za'a iya amfani dashi don ฦ™irฦ™irar abubuwan HTML dangane da ฦ™imar tsararraki ko abu. Ana amfani da NgFor yawanci tare da wasu umarnin Angular kamar ngIf da ngSwitch.

Yadda ake samun fihirisar ngFor element

Kuna iya amfani da madaidaicin maษ“alli don samun fihirisar wani abu a cikin madauki na ngFor. Ma'anar wannan shine kamar haka:

{{i}} โ€“ {{item}}

A cikin wannan misali, madaidaicin "i" zai ฦ™unshi fihirisar madauki na yanzu. Hakanan zaka iya amfani da wannan canjin don samun dama ko gyara abubuwa a cikin lissafin ku.

Shafi posts:

Leave a Comment