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
https://plnkr.co/edit/5d3qNikhaCEuZQbjXGFO?p=info
Any help will be greatly appreciated. Thanks in advance.
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.