Are you certain that _parts in the controller for the top view is always initialized? This problem typically happens when you are loading _parts from an external resource (like an XHR) and it is not initialized in the constructor. My general solution is to always initialize a dummy:
first some comments to your code.
Please do not start interfaces/models with I, if you have a class or interface called PartInfo it is clear you are working with Objects of this type.
Do not do async stuff in the constructor --> use the Life cycle hooks.
import {OnInit} from '@angular/core';
...
class MyComponent implements OnInit {
ngOnInit() {
// requests and async stuff here
}
}
Because object instantiation should not depend on async stuff.
If you are using TypeScript do not prefix private stuff with ā_ā you have the private keyword to do this:
private parts: ....;
And to your base question --> in the constructor functions the databindings are not ready.
So if you set an initial value in the template to your input --> you need to wait until the life cycle hook OnInit gets called.
<my-component [parts]="partList"></my-component>
import {Component, Input, OnInit} from '@angular/core';
...
class MyComponent implements OnInit {
@Input() parts;
constructor() {
// this.parts = undefined
}
ngOnInit() {
// this.parts is initial set!
}
}
Thank you guys for your input. It gave me the help to investigate more about the issue.
What I found is my pipes had issues!
Yep, before I was able to do:
export class OrderBy {
transform(input: IPartInfo[], [orderBy]) {
Now, I need to remove the square brackets to make it work (I also added the PipeTransform, that does not seem to be necessary, but probably cleaner based on Angular.io site)!
export class OrderBy implements PipeTransform {
transform(input: IUnitInfo[], orderBy) {
For now, it is ok, but I just donāt know how it will be possible to pass more than one parameters. I thought the [] were used for that
While I agree with most of your points, not this one. TypeScriptās ability to enforce access control modifiers is limited, and I think naming conventions still have value here.
If you read what @bengtler said above, donāt get the data in the constructor and use ngOnInit. Like you saw, the this.data is there and ready to use.
I my Case the object transfered via @Input() is an Array of objects.
this array is displayed via *ngFor
<ion-card responsive
*ngFor="let date of data" >
<ion-card-content>
<h2>{{date.name}}</h2>
<p>{{date.description}}</p>
</ion-card-content>
....
But only the first card get display correctly, the other, donāt appear. or appear just with every propertie set to nullā¦
so instead of seeing around 10 cards i get one right an 9 empty cards.
The data is retrieved async via nested http-calls.