Following only the pattern of Angular2 the correct syntax would be this:
<div *ngFor="#hero of heroes">{{hero.fullName}}</div>
Where it just replaces the same function of ng-repeat
of Angular 1.x, where it will loop the entire length of your array, you don’t need to specify or know what the extension is. If it’s 5, 10 or 300 ngFor
will go through all. The difference between the ngFor
and the for()
that you refer to, is that the ngFor
is applied directly in the template, ie if you want to do some manipulation of the data before going to the view
, this should be done yet on component
responsible, ai yes you can use the for()
for only later pass to your view (html).
Everything will depend on your goal.
Edited:
I confess I never used Ionic
, but if the logic is the same as using icon-font (which I imagine it is) you can use an ng-class to apply the class corresponding to the amount of votes. For example:
<i [ngClass]="{
'ion-android-star-outline': valorEstrela < 1,
'ion-android-star': valorEstrela >= 1}">
</i>
<i [ngClass]="{
'ion-android-star-outline': valorEstrela < 2,
'ion-android-star': valorEstrela >= 2}">
</i>
<i [ngClass]="{
'ion-android-star-outline': valorEstrela < 3,
'ion-android-star': valorEstrela >= 3}">
</i>
<i [ngClass]="{
'ion-android-star-outline': valorEstrela < 4,
'ion-android-star': valorEstrela >= 4}">
</i>
<i [ngClass]="{
'ion-android-star-outline': valorEstrela < 5,
'ion-android-star': valorEstrela >= 5}">
</i>
Thus, you should only assign the value received from the bank to the property valorEstrela
and it will apply the class corresponding to the fill. Again, as I have never used Ionic
I don’t know if there’s a better option, but I believe that the one I went through should solve your problem in a more practical way.
My goal is not to work with vector... It is a scheme for rating, back of the bank an integer 4 for example. I take this whole and I have to print 4 stars on the screen. But it’s an integer not a vector.
– Hiago Souza
Then it is not ngFor that will use, as it serves to interact by the objects of an array and display each of them on the screen. To achieve its goal would require the use of another logic.
– celsomtrindade
So @Celsomtrindade, I know it’s not, I just used it to expose my need..
– Hiago Souza
It’s this other logic that I’m after, I’ve decided to create a vector by allocating the amount of positions needed which is gambiarra =/
– Hiago Souza
@Hiagosouza Are you using what to display these stars? Icon font?
– celsomtrindade
I’m using the ion-icon directive
– Hiago Souza
@Hiagosouza edited my answer, see if that’s what you’re looking for. = D
– celsomtrindade
Sorry the delay, although I have not tested the above way arrives at the result I expected at the time. Thank you.
– Hiago Souza