Error: Funktion addChild ist nicht vorhanden in FlexboxLayout

I'm struggling with mounting a visualization for data pulled from a REST API using TypeScript. I keep encountering errors when trying to dynamically create the layout, even though the data is being retrieved correctly from the server.

<FlexboxLayout
    flexWrap="wrap"
    #flex
>
</FlexboxLayout>

Here's the TypeScript code:

import { FlexboxLayout } from 'tns-core-modules/ui/layouts/flexbox-layout/flexbox-layout';
import { StackLayout } from 'tns-core-modules/ui/layouts/stack-layout';
import { Image } from 'tns-core-modules/ui/image';
import { Label } from 'tns-core-modules/ui/label';

// ...

@ViewChild('flex',{static: false}) flex: FlexboxLayout;

ngOnInit() {
  // Populate the categories variable with server data

  categories.forEach((cat) => {
    this.createCategView(cat);
  });
}

createCategView(c: Category) {
  let stack = new StackLayout();
  let img = new Image();
  img.src = c.image;
  img.stretch = "none";
  img.width = 25;
  img.height = 25;

  let label = new Label();
  label.text = c.name;

  stack.addChild(img);
  stack.addChild(label);

  this.flex.addChild( stack );
}

Unfortunately, the last line of code this.flex.addChild is throwing an error and saying that it is not a function.

Answer №1

It appears that the only type you can assign to a variable annotated with ViewChild is an Angular Component. This means that you cannot interpret flex as FlexboxLayout, but rather as ElementRef.

@ViewChild('flex',{static: false}) flex: ElementRef;

In addition, using ngOnInit may be too early for this scenario. You might want to consider using ngAfterViewInit or the loaded event of the layout itself instead.

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

What Causes CORS Errors When Sending Encoded Information?

Dealing with poor data quality is a challenge I face. An example of this is when the primary key value of a table contains spaces and special characters, like 35581/H0034-100003 My goal is to retrieve a record by its primary key value using a GET request ...

Attempting to incorporate NestJS modules into an NX monorepo is a task that Angular is currently

Recently, I encountered a frustrating issue while working with a monorepo that contains both Angular and NestJS. In an attempt to access DTOs, I made the mistake of including NestJS files on the client side. This caused Angular compilation errors due to de ...

What steps should I take to resolve the issue with react-redux in my project?

I have been delving into the world of redux recently. I went ahead and installed redux using the following command: npm install -save redux @types/react-redux Despite my best efforts to troubleshoot, the issue persists... These are the dependencies in m ...

No matter how hard I try, npm refuses to ignore my TypeScript source code file

I have a project that I developed using TypeScript and compiled to JavaScript before publishing it as a CLI tool through npm. However, I am facing an issue where the TypeScript source code is being included in the npm package, along with other random .ts f ...

Utilizing TypeScript Generics to Dynamically Set Tag Names in React

I am working on a straightforward polymorphic React component that is designed to render only tag names (such as span) and not custom React components (like MyComponent). I believe this can be achieved using JSX.IntrinsicElements. Here is the code snippet ...

Guide to Integrating BLK Theme into an Angular CLI Project

I've recently set up an Angular project using CLI and I am interested in integrating the BLK theme by Creative Tim into this project. However, the only available option from Creative Tim is to download a pre-existing project and build upon that framew ...

Can I leverage getStaticProps and getStaticPaths within a page component that employs dynamic routing without prior knowledge of the IDs?

I have created a fully static site generation (SSG) app where the backend cannot be accessed during build time. All the data is specific to user permissions, so I cannot specify paths in the getStaticPaths method required for dynamic routed components us ...

Tips for creating a draggable Angular Material dialog

Has anyone been able to successfully implement draggable functionality in an Angular Material Dialog? I've spent a considerable amount of time searching for a definitive answer but have come up empty-handed. Any insights or guidance would be greatly a ...

Troubles with adding a semicolon when configuring cookies in Javascript with Angular

While attempting to implement cookies with TypeScript in Angular, I ran into an unexpected issue. My intention was to save some data in a cookie for future testing purposes. The line of code that caused the problem was: document.cookie = "token=" + value ...

SPFX web part encounters an issue due to lack of support for property or method "includes" in Object

I am facing an issue with my spfx web part version 1.8.2 that is functioning well in Chrome but not in IE11. Initially, the error "Object doesn't support property or method 'find'" was occurring, leading me to include the following packages: ...

What is the reason behind the restriction on creating circular dependencies in Ionic applications?

Working with Ionic, I have created 2 services to provide data: export class DocumentService { constructor(favorisService: FavorisService) { } async GetById(id: number): Promise<DocumentModel>{ let path = this.favorisService.getPath(); ...

There was an error reported by TypeScript stating that Nest.js is not considered a module

During the development of my project using Nest.js, I came across an error that I couldn't find a solution for. The issue arises when I try to export a function from one file and import it into a controller. Even though the function is exported correc ...

Converting changing inputs using Angular 5

I am working with a JSON translation file that contains translations for both English and German languages. Here is an example of the English translation file: en.json "COLORS": { "BLUE": "Blue", "RED": "Red", "GREEN": "Green" } ...

LocalStorage in Angular application failing to function in Android web view

Working with Angular 4, I've developed a web application that stores the user security token in localStorage after login. The application uses this localStorage value to control the visibility of certain links, such as hiding the login button once th ...

Angular Application caught in an infinite loop

Currently, I have an Angular web application that utilizes the @microsoft/microsoft-graph-client to fetch the logged-in user's details. The user is signed in using @azure/msal-angular. In order to log the user in, I have an authentication service that ...

There is no correlationId found within the realm of node.js

Currently, I am in the process of implementing correlationId functionality using express-correlation-id. I am diligently following the guidelines provided on this page: https://www.npmjs.com/package/express-correlation-id. I have successfully imported the ...

Invoke the LazyQuery Hook within a Function

My GraphQL query implementation is as follows: const [loadUsers, { loading, data }] = useLazyQuery(LoadUsersQuery); When I utilize this code snippet in my project, the lazy query loadUsers functions properly and displays the results: return ( <d ...

Sorting complex strings in Typescript based on the dates contained within them

How can I sort a list of 2 strings with dates inside them so that the earlier one always comes first? The date is always after the second comma. For example, const example = ["AAA,5,2020-09-17T21:14:09.0545516Z", "AAA,0,2020-09-03T20:38:08. ...

The type FormGroup<any> lacks the controls and registerControl properties compared to AbstractControl<any>

I've been developing a reactive nested form inspired by this YouTube tutorial - https://www.youtube.com/watch?v=DEuTcG8DxUI Overall, everything is working fine, except for the following error - https://i.sstatic.net/bZHPV.png Below are my files. ho ...

What is the predetermined time limit for an HTTP GET request made using the HttpClient module in Angular 2?

I'm currently investigating the default timeout for an HTTP GET request made with HttpClient in Angular 2. I need to determine if the timeout is occurring at the endpoint due to a large query or if it's caused by the request itself timing out. Un ...