I apologize that I'm a complete beginner to angular2.
I have an array with a list of items and a button that allows users to create new items. Upon clicking the button, users will be asked to list a new item. When the user presses enter, the new item will be stored in an array. This array should then be updated in the ngFor directive.
Here is my current code
export class HelloWorld {
// Declaring the variable for binding with initial value
yourName: string = '';
items = ["pineapple", "apples", "tomatoes", "water"];
addItems() {
newItem = prompt("Enter a new item");
items.push(this.newItem);
}
}
Here is my corresponding view
<button (click)="addItems()">Add Items</button>
<ul>
<li *ngFor="#item of items">{{item}}</li>
</ul>
I created a plunker for this
Any help will be greatly appreciated. Thanks in advance.