I can't understand why instead of a placeholder inside my input I see [object Object];
Here is my html:
<div class="input-form">
<input type="text" placeholder="Type name here..." [(ngModel)]="newItem">
<button (click)="addItem()">Add new</button>
</div>
<ul>
<li *ngFor="let item of items">{{ item }}
<button (click)="deleteItem(item)" >Delete</button>
</li>
</ul>
And here is component.ts:
newItem = {};
items = [];
addItem() {
if (this.newItem !== null) {
this.items.push(this.newItem);
this.newItem = {};
}
}
[object Object] is result of toString() function.
const obj = { };
console.log(obj.toString());
result:
[object Object]
You need to pass value of string type, but I highly recommend not to pass value with ngModel at all. You should use FormGroup to create forms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With