question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Correct way to use ngFor loop on selector directive? It doesn't seem to work.

See original GitHub issue
   <div class="cards-flex-container">
      <mz-card *ngFor="let Package of packages; last as isLast; odd as isOdd" class="col-12" [class.last-col]="isOdd">
            <p><span class="key">Package Name:</span>
               <span class="value">{{ Package.Name }}</span>
            </p>
            <p>
               <span class="key">Description:</span>
               <span class="value">{{ Package.Description }}</span>
            </p>
            <p>
               <span class="key">Price:</span>
               <span class="value">${{ Package.OriginalPackagePrice }}</span>
            </p>
            <p>
               <span class="key">Package Discount:</span>
               <span class="value">{{ Package.Discount.Amount * 100 }}%</span>
            </p>
            <p class="no-margin-bottom">
               <span class="key">Package Price:</span>
               <span class="value">${{ Package.DiscountedPackagePrice }}</span>
            </p>
            <!--<hr *ngIf="!isLast" />-->

      </mz-card>
   </div>

This does not work. It produces blank cards. But if I change

selector_directives_doesnt_work

<mz-card *ngFor="let Package of packages; last as isLast; odd as isOdd" class="col-12" [class.last-col]="isOdd">

to

<div *ngFor="let Package of packages; last as isLast; odd as isOdd" class="card-panel col-12" [class.last-col]="isOdd">

It works as expected. selector_directive_works

Expected Behavior

Interpolation should work inside of selector directives.

Current Behavior

It doesn’t work.

If this is a big change, I can just continue using regular Materialize, since it doesn’t provide much gain to use the selector directive. But I wanted to bring it to your attention since it might be happening with other selector directives as well.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
scotecommented, Oct 30, 2017

This will be fixed in our next release.

1reaction
scotecommented, Oct 18, 2017

You need to include your content inside <mz-card-content> tag.

<div class="cards-flex-container">
  <mz-card *ngFor="let Package of packages; last as isLast; odd as isOdd" class="col-12" [class.last-col]="isOdd">
    <mz-card-content>
      <p><span class="key">Package Name:</span>
          <span class="value">{{ Package.Name }}</span>
      </p>
      <p>
          <span class="key">Description:</span>
          <span class="value">{{ Package.Description }}</span>
      </p>
      <p>
          <span class="key">Price:</span>
          <span class="value">${{ Package.OriginalPackagePrice }}</span>
      </p>
      <p>
          <span class="key">Package Discount:</span>
          <span class="value">{{ Package.Discount.Amount * 100 }}%</span>
      </p>
      <p class="no-margin-bottom">
          <span class="key">Package Price:</span>
          <span class="value">${{ Package.DiscountedPackagePrice }}</span>
      </p>
      <!--<hr *ngIf="!isLast" />-->
    </mz-card-content>
  </mz-card>
</div>
Read more comments on GitHub >

github_iconTop Results From Across the Web

angular - *ngIf and *ngFor on same element causing error
I know the easy solution is to move the *ngIf up a level but for scenarios like looping over list items in a...
Read more >
How to Use the ngFor Angular Directive - MakeUseOf
The ngFor directive allows you to repeat the same block a specified number of times, or loop through an array of objects to...
Read more >
Angular *ngFor and *ngIf Directives Explained for Beginners
Let's talk about *ngFor first. You use the *ngFor directive to traverse over an array object and display the data in the UI....
Read more >
Angular Optimization: Use trackBy Option for *ngFor Directive
In the ngDoCheck we use the diff method to detect changes in the items list. If there are changes, we iterate through the...
Read more >
Angular ngFor - Learn All Features, Not Only For Arrays
In this post we are going to go over the ngFor core directive, namely we are ... a loop variable named hero is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found