#setTimeOut
29 messages · Page 1 of 1 (latest)
What's the error?
I try
setTimeOut(() => {
config: {
[key: string]: string;
} = {
title: 'Lista zadań',
footer: '© Lista Zadań, Angular build app',
date: new Date().toDateString(),
};
}
and all code are underline
Now I look up, because I close and open VSCode
Try this
export class AppComponent {
config: Record<string, string>
constructor() {
setTimeout(() => {
this.config = {
title: 'Lisa Zadan',
}
}, 500)
}
}
it doesn't worked
I changed to the earlier code
config: {
[key: string]: string;
} = {
title: 'Lista zadań',
footer: '© Lista Zadań, Angular build app',
date: new Date().toDateString(),
};
I have updated it
can you copy the whole file please
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
config: Record<string, string | Date>
constructor() {
setTimeout(() => {
this.config = {
title: 'Lisa Zadan',
}
}, 500)
}
}
yes, please
Check this
Can you highlight on config and see what error is being complained about.
okay I see, change it to this:
config: Record<string, string> | null = null
add *ngIf="config" on nav-wrapper element
nothing
All previous errors are due to Typescript expecting you to define and initialize data.
For the last one, based on your type, Typescript can't know if there will be a 'title' property.
If you know better, define your config as so: using Record as you did would be only useful for dynamic keys.
or
config: {
[key: string]: string;
title: string;
}
config['title'] or
create a type on config:
interface Config {
title: string
footer: string
date: string
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
config: Config | null = null
}
Your HTML
<div class="nav-wrapper" *ngIf="config">
{{config.title}}
</div>
Please review #rules and avoid tagging people randomly. I never used a single chart library so don't know about multiple ones.