I'm trying to display some data from my component to the html. What confuses me is the fact that in older component files this worked. Now, in a few new ones I've created, it only starts working after logging in and refreshing the page.
My component.ts file:
import {Component} from '@angular/core';
import {DataService} from '../../services/data.service';
import {ActivatedRoute, Router} from '@angular/router';
import * as $ from 'jquery/dist/jquery.min.js';
import 'jquery-ui/jquery-ui.min.js';
declare let jQuery: any;
@Component({
templateUrl: '../../templates/plan/general-info.html',
})
export class GeneralInfoComponent {
data;
selectedCompany = null;
selectedPlace = null;
constructor(private dataService: DataService,
private router: Router,
private route: ActivatedRoute) {
this.data = this.route.parent.snapshot.data;
this.selectedCompany = this.data.companies[0];
this.selectedPlace = this.dataService.selectedPlace.getValue();
}
}
The troubling part of my template file:
<div class="general-data">
<h3>{{selectedCompany.name}}</h3>
<h3>Reg nr {{selectedCompany.regCode}}</h3>
<h3>{{selectedCompany.address}}</h3>
<h3>{{selectedCompany.phone}}</h3>
<h3>{{selectedCompany.email}}</h3>
<h3>{{selectedCompany.contactPerson}}</h3>
<h3>{{selectedCompany.personCode}}</h3>
</div>
<div class="general-data">
<h3>{{selectedPlace.name}}</h3>
<h3>{{selectedPlace.address}}</h3>
<h3>{{selectedPlace.contactPerson}}</h3>
<h3>{{selectedPlace.phone}}</h3>
<h3>{{selectedPlace.email}}</h3>
<h3>{{selectedPlace.personCode}}</h3>
</div>
I don't want to write another hack to display the data with jQuery. The weird part is that the data is nicely displayed after refreshing as if it didn't get the data the first time I load the page. Is something like that even possible?
NOTE: When logging the data right after giving values to this.selectedCompany and this.selectedPlace, it displays correct info in console.
My question: how to get it working straight away without having to refresh the page?
I've been messing with this the whole day and would love a solution.
Thanks in advance.
Resolveservice, which resolves the companies. And please don't use jQuery. You will get lost too quickly if you use jQuery and angular together :)datamember of the route parent set? what is your router configuration? Debug an check ifthis.route.parent.datais defined.