0

I've files named as server.component.ts and server.component.html.

My server.component.ts file looks like this.

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

@Component({
  selector: 'app-server',
  templateUrl: './server.component.html',
  styles : [
    `.online {color : white;
    }`]
})
export class ServerComponent {
  serverId : number= 10;
  serverStatus : string = 'offLine';
  paragraphName : 'Paragraph01';
  showSecret = false;
  log = [];

  constructor(){
    this.serverStatus = Math.random() > 0.5 ? 'online' : 'offline';
  }

  getServerStatus(){
    return this.serverStatus;
    
  }
  getColor(){
    return this.serverStatus === 'online'? 'Green':'Red';
  }

  onToggleDisplay(){
    this.showSecret = !this.showSecret;
    this.log.push(this.log.length + 1);
  }
}

and server.component.html file looks like :

<button class = "btn btn-primary" (click) = "onToggleDisplay()">Display Details</button>
<p *ngIf  ="showSecret">Secret Password = tuna</p>
<div *ngFor = "Let logItem of log ">{{ logItem }}</div>

I am trying to print log item which should return log after clicking on Display Details button. But nothing's happening.

I am new to Angular.

2
  • 1
    use small letter for let => <div *ngFor = "let logItem of log ">{{ logItem }}</div> Commented Jul 30, 2020 at 11:59
  • 1
    It's a typo. *ngFor="Let ... should be *ngFor="let ... Commented Jul 30, 2020 at 11:59

2 Answers 2

3

modify this line , there is no Let, its let (with small letters)

<div *ngFor = "let logItem of log ">{{ logItem }}</div>

Here is the demo

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

Comments

1

When you're doing a ngFor, you should let item of itens. It's written Let. Maybe that is the problem

<button class = "btn btn-primary" (click) = "onToggleDisplay()">Display Details</button>
<p *ngIf  ="showSecret">Secret Password = tuna</p>
<div *ngFor = "let logItem of log ">{{ logItem }}</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.