Here is the code snippet I am working with:
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<h1>Hello {{name}}</h1>
<p><strong>Email:</strong> {{email}}</p>
<p><strong>Address:</strong> {{address.street}}, {{address.city}}, {{address.country}}.</p>
`,
})
export class AppComponent {
name = 'Strahinja';
email = '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0d7e797f6c656463676c4d6a606c6461236e6260">[email protected]</a>';
address = {
street: 'Boulevard of king Alexander',
city: 'Belgrade',
country: 'Serbia'
}
addressToString(): string {
return this.address.street + ', ' + this.address.city + ', ' this.address.country;
}
}
I am trying to print out the following line:
Address: Boulevard of king Alexander, Belgrade, Serbia
. However, what I am actually getting as output is Address: [object Object]
, which is not the desired result. I am aware that I can achieve the correct output by using {{address.street}}, {{address.city}}, {{address.country}}
. Additionally, I have attempted to create a toString()
method similar to Java, but encountered a compilation error regarding the last usage of this
. The error message states: ';' expected. Unreachable code detected.
Can you provide any suggestions or insights? Is it possible that TypeScript only allows for accessing 2 attributes in a Class?