0

I have followin problem:

enter image description here

When I tied to get addons I just get [] but web console show me that I have addons.

My json structure:

enter image description here

I just tried to do this:

console.log(vehicle.montage_card.addons); but I have this result: []

What am I doing wrong?

EDIT

I have PrimeNg table, this is little part of this table:

      <ng-template let-col let-vehicle="rowData" let-index="rowIndex" pTemplate="editor">
        <p-multiSelect *ngIf="!viewMode && (continuationContract == 0)" name="client_vehicles{{index}}" [showToggleAll]="false" [style]="{'width':'100%'}"
          [options]="clientVehiclesOptions" defaultLabel="Open list" [ngModel]="vehicle.assignedContractsID" (ngModelChange)="onSelectedClientVehiclesChange($event, vehicle)"
          maxSelectedLabels=0 selectedItemsLabel="Wybrano: {0}." (onChange)="checkSelectedClientVehiclesQuantity(vehicle)"
          [disabled]="viewMode">
        </p-multiSelect>
      </ng-template>

And this is my function when I console.log the vehicle:

onSelectedClientVehiclesChange(event: any, vehicle: Vehicle) {

let temp: any[] = [];
let numberExists: boolean = false;
console.log("vehicle");
console.log(vehicle);
console.log(vehicle.montage_card.addons);

event.forEach(element => {
  temp.push(this.clientVehicles.client_vehicles.find(clientVehicle => clientVehicle.id == element));
});
}
4
  • 5
    And where are you console logging this? Impossible to help if we don't know this. Please show your code. Commented Oct 9, 2018 at 8:55
  • 1
    Also another note, never post just images of code. Always add code to question as code blocks :) Commented Oct 9, 2018 at 8:59
  • the way you access the addons is correct like vehicle is the object inside that object there is another object called montage_card , inside that the array of addons consist. Can you post the code Commented Oct 9, 2018 at 9:03
  • is it a ajax call ? where you get the response Commented Oct 9, 2018 at 9:05

2 Answers 2

2

When you output the data, addons were not populated but there is a place to populate data which is later than output or using the data in timely manner. For example, populating data from the server using ajax.

Since the data you printed is object which means the reference to the memory space, when you open this after data populated in console, you will see addons.

That's why it says no addons but has addons when you expand it.

To use data, make sure you use it after data population. Pay attention to asynchronous actions.

Sign up to request clarification or add additional context in comments.

Comments

-1

Try using following format:

console.log(vehicle['montage_card']['addons']);

1 Comment

using dot and inside brackets you can access the object properties , you can read this one where you use dot vs brackets stackoverflow.com/questions/4968406/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.