Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4870

Cannot read property 'get' of undefined

$
0
0

Hello everyone! I created a purchases controller to take data from user input, but I have an error;

routes/purchases.js:

import Route from '@ember/routing/route';

export default class PurchasesRoute extends Route {
}

controllers/purchases.js:

import Controller from '@ember/controller';
import { action } from '@ember/object';

export default class PurchasesController extends Controller {
    @action
    addPurchase() {
        var pname = this.get('PurchasesController').get('pname');
        var pprice = this.get('PurchasesController').get('pprice');
        console.log(pname, pprice);
    }
}

purchases.hbs:

{{page-title "Purchases"}}

<div class="purchases">

<h3>Add Purchase</h3>

<div class="input-field">
    {{input placeholder="Purchase Name" type="text" class="validate" value=pname}}
    {{input placeholder="Purchase Price" type="text" class="validate" value=pprice}}
</div>

<a class="waves-effect waves-light btn" {{on 'click' this.addPurchase}}>Add Purchase</a>

</div>

{{outlet}}

error:

Uncaught TypeError: Cannot read property 'get' of undefined
    at PurchasesController.addPurchase (purchases.js:15)

Thanks in advance for your help!

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 4870

Trending Articles