You can see that it is showing "push" property undefined. Here, you get some useful information about errors.
Let's check component.ts file:
- import { Component } from '@angular/core';
-
- @Component({
- selector: 'app-root',
- templateUrl: './app.component.html',
- styleUrls: ['./app.component.css']
- })
- export class AppComponent {
- title = 'testing-app';
- servers;
-
- OnAddServer() {
- this.servers.push('Another Server Added');
- }
-
- onRemoveServer(id: number) {
- const position = id + 1;
- this.servers.splice(position, 1);
- }
- }
Here, we have declared servers but it is not initialized. So, we set it to be in array format to keep newly created servers. So, change it to:
- servers= [];
Change the component.ts:
- import { Component } from '@angular/core';
-
- @Component({
- selector: 'app-root',
- templateUrl: './app.component.html',
- styleUrls: ['./app.component.css']
- })
- export class AppComponent {
- title = 'testing-app';
- servers = [];
-
- OnAddServer() {
- this.servers.push('Another Server Added');
- }
-
- onRemoveServer(id: number) {
- const position = id + 1;
- this.servers.splice(position, 1);
- }
- }