- I'm following a tutorial to create an expense entry app, which can be found on page 33 of this tutorial link.
I encountered the following error - Property 'expenseEntry' does not exist on type 'ExpenseEntryComponent'. I've looked into these resources:
a) Angular error TS2339 Property does not exist on type
b) Angular - How to fix 'property does not exist on type' error?
but I didn't find a clear solution.
- Here is my expense-entry.ts file:
import { Component } from "@angular/core";
import { OnInit } from "@angular/core";
export interface ExpenseEntry {
id: number;
item: string;
amount: number;
category: string;
location: string;
spendOn: Date;
createdOn: Date;
}
@Component({
template: ''
})
export class ExpenseEntryComponent implements OnInit{
title: string;
expenseEntry: ExpenseEntry;
constructor(){ }
ngOnInit(){
this.title = "Expense Entry";
this.expenseEntry = {
id: 1,
item: "Pizza",
amount: 21,
category: "Food",
location: "Zomato",
spendOn: new Date(2020, 6, 1, 10, 10, 10),
createdOn: new Date(2020, 6, 1, 10, 10, 10),
};
}
}
- Here is my expense-entry.component.ts file:
import { Component, OnInit } from '@angular/core';
import {ExpenseEntry} from '../../app/expense-entry/expense-entry'
@Component({
selector: 'app-expense-entry',
templateUrl: './expense-entry.component.html',
styleUrls: ['./expense-entry.component.css']
})
export class ExpenseEntryComponent implements OnInit {
title: string | undefined;
constructor() { }
ngOnInit(): void {
this.title = "Expense Entry";
}
}
- Here is my expense-entry.component.html file:
<!------------------content------->
<div class="container">
<div class="row">
<div class="col-lg-12 text-center" style="padding-top: 20px;">
<div class="container" style="padding-left: 0px; padding-right:0px;">
<div class="row">
<div class="col-sm" style="text-align: left;">{{title}} </div>
<div class="col-sm" style="text-align: right;"> <button type="button" class="btn btn-primary">Edit</button>
</div>
</div>
</div>
<div class="container box" style="margin-top: 10px;">
<div class="row">
<div class="col-2" style="text-align: right;"> <strong><em>Item :</em></strong></div>
<div class="col" style="text-align: left;">{{expenseEntry.item}}</div>
</div>
<div class="row">
<div class="col-2" style="text-align: right;"> <strong><em>Amount :</em></strong></div>
<div class="col" style="text-align: left;">{{expenseEntry.amount}}</div>
</div>
<div class="row">
<div class="col-2" style="text-align: right;"> <strong><em>Category :</em></strong></div>
<div class="col" style="text-align: left;"> food</div>
</div>
<div class="row">
<div class="col-2" style="text-align: right;"> <strong><em>Location :</em></strong></div>
<div class="col" style="text-align: left;">{{expenseEntry.location}}</div>
</div>
<div class="row">
<div class="col-2" style="text-align: right;"> <strong><em>Spend on :</em></strong></div>
<div class="col" style="text-align: left;">{{expenseEntry.spendOn}} </div>
</div>
</div>
</div>
</div>
</div>
- Inserting {{expenseentry.item}} causes an error. I've tried restarting the server but it doesn't seem to work.