[Bug] *ngFor in span/formattedString
See original GitHub issueFrom @mikraus94 on November 15, 2016 13:29
Hi,
I’m trying to make *ngFor for span but without success.
It stacks texts under selfs
<Label *ngFor="let span of spans> <FormattedString> <Span [text]="span.text" [fontAttributes]="span.att"></Span> </FormattedString> </Label>
It doesn’t work for
<Label> <FormattedString *ngFor="let span of spans> <Span [text]="span.text" [fontAttributes]="span.att"></Span> </FormattedString> </Label>
or
<Label> <FormattedString> <Span *ngFor="let span of spans [text]="span.text" [fontAttributes]="span.att"></Span> </FormattedString> </Label>
It shows only first object from spans array.
Can you help me or this is bug?
Thank you
Copied from original issue: NativeScript/NativeScript#3099
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
bug in angular when data bing inside ngfor loop
The reason that the iShouldrepeatOneTime method is called 4 times is because of Angular's default ChangeDetectionStrategy.
Read more >ngFor for iterable not working : r/Angular2 - Reddit
The issue is angular's template expression language is not javascript. There's a lot of overlap, and you can do a fair amount, but...
Read more >NgForOf - Angular
The ngForOf directive is generally used in the shorthand form *ngFor . In this form, the template to be rendered for each iteration...
Read more >DataGrid does not render columns in the required order when ...
To render ethe columns, I'm iterating through an array that contains the columns using an ngFor, The same ngFor used with this simple...
Read more >Angular ngFor - Learn All Features, Not Only For Arrays
What is the syntax of ngFor ? · we are passing to ngFor an iteration expression · a loop variable named hero is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Some updates:
<Label><FormattedString *ngFor="let span of spans"> ...
will never work as label can have only a singleFormattedString
.span
s insideFormattedString
is allowed, so<Span *ngFor="let span of spans" ...
sounds reasonable. However, when having a structural directive (*ngFor
) angular actually inserts a marker element to keep track of where to add and remove the items. This marker not a valid element to be inserted insideFormattedString
, so probably this is the reason the code is not working.You can create a simple pipe to overcome this issue:
In a case you don’t actually need the styling of the different spans to be different - this will do the job.
Just wanted to ping some curiosity here as well - just ran into this tonight 😦