0

I'm using Angular 5 and doing a crash course. I've actually gotten further than just using an ngFor directive, but I'm doing part of a practice assignment and one of the first things I'm trying to do won't loop to display data. I have other projecdts where it's working but this one doesn't and I'm baffled. Know it's something silly.

Component

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  subscriptions: ['Basic', 'Advanced', 'Pro'];
}

HTML Template

<div class="container">
  <div class="row">
    <div class="col-xs-12>
      <p *ngFor="let subscription of subscriptions">{{subscription}}</p>
    </div>
  </div>
</div>

Simple, yeah? I was actually putting it into an option element for a select input, but that didn't work and so I figured I'd try something even simpler and it still won't work. THe resultant html has this where the content would go, but I'm not versed enough to know what that really means.

thanks

1
  • 1
    subscriptions: ['Basic', 'Advanced', 'Pro']; is setting the type. You need to assign the value with =. Commented Apr 12, 2018 at 3:42

2 Answers 2

2

You need to assign the array value

 subscriptions =  ['Basic', 'Advanced', 'Pro'];

DEMO

Sign up to request clarification or add additional context in comments.

2 Comments

Adding to this if I was you I wouldn't use types (or myvariable: myType) as of yet until you get the hang of TypeScript or Angular. It will just complicate your life. Is not needed either way in most occasions. When you need it you will know ;)
Oh my gosh. Thank you. I knew it was something silly. I've been training for weeks non-stop and I'm tired. I appreciate it. Will accept as answer when I can (have to wait 10 minutes)
0

You can display each array data in list Using *ngFor in Angular.

This array assign is wrong in your code.

export class AppComponent {
  subscriptions: ['Basic', 'Advanced', 'Pro'];
}

Array assign should be :

export class AppComponent {
  subscriptions =  ['Basic', 'Advanced', 'Pro'];
}

more details

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.