0

html code

<div class="container">
  <div class="row">
    <div class="col-xs-12">
      <p>Add new Servers or blueprints!</p>
      <label>Server Name</label>
      <input type="text" class="form-control" [(ngModel)]="newServerName">
      <label>Server Content</label>
      <input type="text" class="form-control" [(ngModel)]="newServerContent">
      <br>
      <button
        class="btn btn-primary"
        (click)="onAddServer()">Add Server</button>
      <button
        class="btn btn-primary"
        (click)="onAddBlueprint()">Add Server Blueprint</button>
    </div>
  </div>
  <hr>
  <div class="row">
    <div class="col-xs-12">
      <div
        class="panel panel-default"
        *ngFor="let element of serverElements">
        <div class="panel-heading">{{ element.name }}</div>
        <div class="panel-body">
          <p>
            <strong *ngIf="element.type === 'server'" style="color: red">{{ element.content }}</strong>
            <em *ngIf="element.type === 'blueprint'">{{ element.content }}</em>
          </p>
        </div>
      </div>
    </div>
  </div>
</div> 

ts code

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

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  serverElements = [];
  newServerName = '';
  newServerContent = '';

  onAddServer() {
    this.serverElements.push({
      type: 'server',
      name: this.newServerName,
      content: this.newServerContent
    });
  }

  onAddBlueprint() {
    this.serverElements.push({
      type: 'blueprint',
      name: this.newServerName,
      content: this.newServerContent
    });
  }
}

errors in the terminal

app.component.html errors

  1. Property 'name' does not exist on type 'never'
  2. Property 'type' does not exist on type 'never'
  3. Property 'content' does not exist on type 'never'
  4. Property 'type' does not exist on type 'never'
  5. Property 'content' does not exist on type 'never'

app.component.ts errors

  1. Argument of type '{type: string; name: string; content: string; }' is not assignable to parameter of type 'never'
  2. Argument of type '{type: string; name: string; content: string; }' is not assignable to parameter of type 'never'
  • Answer is here: https://stackoverflow.com/a/52423919/1858357 – BizzyBob Sep 28 '22 at 14:09
  • Does this answer your question? [What is "not assignable to parameter of type never" error in TypeScript?](https://stackoverflow.com/questions/52423842/what-is-not-assignable-to-parameter-of-type-never-error-in-typescript) – BizzyBob Sep 28 '22 at 14:10
  • @BizzyBob No, still getting same errors – user19610519 Sep 28 '22 at 14:14
  • 1
    What change did you attempt? Works [here](https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgGIHt3IN4FgBQyyYAngA4QBcyAzmFKAOYDcBRIcAtlbfU64WQJ04COGp0GIFgQC+BAhAAeZdFDBCANnBo1kAQTJkAwuk6qQYjXkE1oAN2gBRTRG7g9AXmQBtALrMREHBQQD0ochOAEpRAPJRbMjhtA7Oru5gNNQY6P7I3v6BSRGoAJIAGomWAO4AyqlQAHJcKN4A5G0C7BB1Daai4PnIHQKJIvoAJhP1UI5QABQAlDiJRGAAFsA0AHR2s2luVjtkAK406-M2IcTkPG17c20ANKtBHNzUG1vbNTNzzdwXoJgsIBmBPpsdr8+iJIOBXrJFl1kPJ8GMQJMJgAhTQnCBkKRgJYrYHESG7BouQ4ebanc6XV5rW7UNoAI1x+MJz0ZyHePC+UJ6f2gAIgQOuoLh4LJ32h+yg-SlCKRiVRsiAA). – BizzyBob Sep 28 '22 at 14:18

0 Answers0