A guide to successfully transferring data array values from a Parent Component to a Child Component using APIs in Angular

To transfer values of

this.bookingInfo = bookings.responseObj.txnValues;
array from the parent component to the bookingInfo array in my child component and then insert that data into the chartNameChartTTV.data = []; array in the child component. Here, divName will be referencing an HTML file
am4core.create('divName', am4charts.XYChart);
rather than the bookingInfo array.

This code belongs to my parent component.

@Component({
      selector: 'app-dashboard',
      templateUrl: './dashboard.component.html',
      styleUrls: ['./dashboard.component.scss']
    })
    export class DashboardComponent implements OnInit{

      bookingInfo = [];
      ngOnInit() {
       this.getBookingInfo();
      }

      getBookingInfo() {
          const params = [];
          params.push({code: 'dateType', name: 'BOOKING'});
          params.push({code: 'fromDate', name: '2019-01-01'});
          params.push({code: 'toDate', name: '2019-12-31'});

          this.ServiceHandler.getTxnInfo([], params).subscribe(
            bookings => {
              this.bookingInfo = bookings.responseObj.txnValues;
              console.log(this.bookingInfo);
          });
      }
    }

This code is from my child component.

@Component({
  selector: 'app-summary-chips',
  templateUrl: './summary-chips.component.html',
  styleUrls: ['./summary-chips.component.scss']
})
export class SummaryChipsComponent implements OnInit {

  @Input() bookingInfo: [];
  ngOnInit() {

     console.log(this.bookingInfo);
  }

   createSummaryChips(  divName: string, chartDataInfo: [], chartValue: any, chartDate: any) {

    am4core.useTheme(am4themesAnimated);

    const chartNameChartTTV = am4core.create('divName', am4charts.XYChart);

    chartNameChartTTV.width = am4core.percent(100);
    chartNameChartTTV.height = am4core.percent(100);
    chartNameChartTTV.padding(0, 0, 0, 0);
    chartNameChartTTV.data = [];
   }

}

This is my service class.

@Injectable({
  providedIn: 'root'
})
export class ServiceHandler {
  getTxnInfo(headers: any[], params: any[]) {
    return this.apiService.get( 'analytics-api/dashboard/txn-info', headers, params);
  }
}

However, when I attempt to console.log(this.bookingInfo); in the child component, it displays an error indicating "undefined". This is the content from my dashboard.component.html file.

   <div class="l-content-wrapper c-summary-chip oh" >
          <div class="c-summary-chip__txt">Cancellations</div>
          <div id="divName" class="c-summary-chip__graph ">
          </div>
    </div>

However, I wish to move this code block to summary-chips.component.html and include in dashboard.component.html like this:

 <div class="l-content-wrapper c-summary-chip oh" style="visibility: hidden">
           <app-summary-chips></app-summary-chips>
    </div>

Answer №1

Don't forget to include the booking information from your dashboard into the app-summary-chips input field

Within the HTML of your dashboard component:

<div class="l-content-wrapper c-summary-chip oh" style="visibility: hidden">
     <app-summary-chips [bookingInfo]='bookingInfo'></app-summary-chips>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to circumvent ng switch and create a component based on type

In my current code, I have an array called resourceTypes and I am using ngSwitch to create different components/directives based on the TypeName. However, I find this approach cumbersome as I have to update the code every time I add a new resource editor. ...

Perform a delayed evaluation of the length of the @Input() array

In my Component, I am utilizing an @Input() ids: string[] = []; variable to check if the length equals 1 in the DOM. <mat-expansion-panel *ngFor="let id of ids" [expanded]="ids.length === 1"> ... </mat-expansion-panel> However, when I append ...

Dynamically setting properties in a Vue component using Angular

After browsing through this interesting discussion, I decided to create a web component: <my-vue-web-comp [userId]="1"></my-vue-web-comp> Initially, everything was working smoothly in Angular when I assigned a static property. Howeve ...

activating a component by interacting with another component

How can I pass the uuid from parent to child component through a click event in Angular? App.component.ts import { Component } from '@angular/core'; import { v4 as uuid } from 'uuid'; @Component({ selector: 'my-app', tem ...

Implementing type inference for response.locals in Express with TypeScript

I need to define types for my response.locals in order to add data to the request-response cycle. This is what I attempted: // ./types/express/index.d.ts declare global { declare namespace Express { interface Response { locals: { ...

Is it possible to confirm that a value is a valid key without prior knowledge of the object's keys during compile-time?

Is there a way in TypeScript to declare that a variable is a keyof some Record without prior knowledge of the keys? For instance, consider an API response returning JSON data. Is it possible to define a type for the keys of this payload to ensure that whe ...

How can I assign a true or false value to an input variable in HTML using AngularTS?

I copied the following HTML code: <tag-input fullWidth id="inputDir" formControlName="inputDir" [modelAsStrings]="true" [placeholder]="'choice feature'" ...

Having trouble with the ngx-slick-carousel installation

I have been attempting to add the slick-carousel library to my Angular project by following the instructions outlined here: https://www.npmjs.com/package/ngx-slick-carousel. The first two steps, which are: npm install jquery --save npm install slick-caro ...

Issue with accessing container client in Azure Storage JavaScript library

When working on my Angular project, I incorporated the @azure/storage-blob library. I successfully got the BlobServiceClient and proceeded to call the getContainerClient method, only to encounter this error: "Uncaught (in promise): TypeError: Failed ...

Error with object props in React using Typescript

Here's a scenario; I have a list of 'Reviews' that I am trying to render. The Proptype for these reviews is as follows: export interface Props { title: string; name: string; reviewdesc: string; rating: number; } In the pare ...

Identify all the CHECKBOX elements that are visible and not concealed

On my page, I have various checkboxes - some with hidden=true and others with hidden=false attributes. Despite trying to use a selector or jQuery to locate checkboxes with the hidden property, I am still facing some challenges. My goal is to differentiate ...

Utilizing a method from a separate class in Ionic 2

Having trouble using the takePicture() function from camera.ts in my home.ts. I keep getting an error message saying "No provider for CameraPage!" Any assistance on how to resolve this issue would be greatly appreciated, as I am new to this language and ju ...

Managing multiple HTTP requests and awaiting all to finish with Angular's RxJs Observables

In my current project, I am working with Observables. I have a unique use case where: Initially, I need to retrieve "pages" from a service that provides Page[] For each of the retrieved "pages," I must fetch the corresponding "sections" from another serv ...

Expanding on the http class to utilize custom properties within Angular2 typescript

I have developed a CustomHttp class that extends Http similar to the example provided here: To integrate this CustomHttp class, I included providers in the bootstrap function as shown below: bootstrap([ HTTP_PROVIDERS, { provide:Http, use ...

Encountering a TypeScript issue when integrating @material-tailwind/react with Next.js 14

Attempting to incorporate "@material-tailwind/react": "^2.1.9" with "next": "14.1.4" "use client"; import { Button } from "@material-tailwind/react"; export default function Home() { return <Button>Test MUI</Button>; } However, the button i ...

Ways to reverse bypassSecurityTrustHtml and convert SafeValue to a string

When I generate HTML and insert it into my webpage, I use the following code: let data = '<font color=blue>hello world</font>'; this.safevalue = this.domSanitizer.bypassSecurityTrustHtml(data); In another part of my code, I needed t ...

Encountering type-checking errors in the root query due to the specific types assigned to my root nodes in a GraphQL and TypeScript application built using Express

As I delve into the world of typescript/graphql, I encountered a peculiar issue while trying to define the type for one of my root nodes. The root node in question simply fetches a user by ID in the resolve function, and thus, I assigned the 'type&apo ...

Manipulate inherited CSS styles from an external source

Currently, I am working on creating a pagination using the NG-Bootstrap pagination component. However, I encountered an issue where I need to modify or specifically remove some CSS properties that are applied by default in the NG-Bootstrap library. Is ther ...

By utilizing a function provided within the context, React state will consistently have its original value

After passing functions from one component to its parent and then through context, updating the state works fine. However, there is an issue with accessing the data inside these functions. They continue to show as the initial data rather than the updated v ...

Examining form functionalities: angular2 form testing

Currently, I'm facing an issue while attempting to test a component that utilizes 'FormGroup' and 'FormBuilder'. Whenever I run the test file for this particular component, I encounter an error stating that 'FormGroup' an ...