How to get value of input ember


#1

Wanted to get the input value, but looking at the console.log it show that this value is undefined. Anyone here who know how to solve that.

import Route from ‘@ember/routing/route’;

export default Route.extend({ actions: { addProduct: function() { var product = this.get(‘product’); console.log(product); } } });

Product {{input type="text" class="form-control" value=product placeholder="Product Name"}}
<div class="form">
	<label>Price</label>
	{{input type="text" class="form-control" value="price" placeholder="Price"}}
</div>

<div class="form">
	<label>Amount</label>
	{{input type="text" class="form-control" value="amount" placeholder="Add Task"}}
</div>
<button {{action 'addProduct'}} class="add-button">Submit</button>

#2

I believe there are two separate issues holding you back.

First, you need to remove the quotations surrounding your value attributes. e.g. value=price

Second, you will need to use this.get('controller').get('price') instead of this.get('price')

I have thrown together the following example that should demonstrate a working input.


#3

Thanks for helping me!!