In Angular 9, there seems to be an issue with the initialization of @ContentChildren

My directive, named "VerticalTabsDirective," has the following properties-

@ContentChildren(MatTabLink) contentChildren: QueryList<MatTabLink>;
@Input() exlVerticalTabs

In my component, I am utilizing this directive with a recursive ng-template in the following manner-

 <nav mat-tab-nav-bar
             [exlVerticalTabs]="selectedIndex">
            <ng-template #recursiveNavList let-tabs="tabs" let-level="level">
                <ng-container *ngFor="let tab of tabs; let i = index">
                    <a mat-tab-link
                       [active]="rla.isActive"
                       [routerLink]="[tab.link]"
                       #rla="routerLinkActive"
                       routerLinkActive>
                            <span>
                               {{tab}}
                            </span>
                    </a>

                    <div>
                        <ng-container *ngTemplateOutlet="recursiveNavList; context: { tabs: tab.subCategories, level: level + 1}"></ng-container>
                    </div>

                </ng-container>
            </ng-template>

            <ng-container *ngTemplateOutlet="recursiveNavList; context: { tabs: profileOutputService.facets, level:0}"></ng-container>

        </nav>

However, during debugging, I noticed that the "contentChildren" property is not initializing correctly. The "_results" object inside remains empty and does not contain the expected "MatTabLink" fields. Strangely, this issue only occurs when using recursion within ng-template.

Has anyone encountered and resolved this issue before?

Answer №1

` element, I came across a solution that has the potential to assist individuals by simply including "{descendants: true}". The code snippet provided below demonstrates how to utilize this improvement:
 @ContentChildren(ChildComponent, { descendants: true}) children: QueryList<
    ChildComponent>

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

Testing @microsoft/applicationinsights-web within an Angular project on a local environment

How can I test Microsoft's application insights locally? Most guides I've come across suggest testing it on the Azure portal, but I can't do that as it would mean testing it in a production environment. ...

Tips for troubleshooting a Keycloak-enabled Angular/Java/Spring application:

Recently, I developed a basic application that leverages keycloak for managing user authentication. However, I am interested in making certain routes accessible to the public. For example, something along the lines of localhost:4200/public-route. I attemp ...

You are able to use a null type as an index in angular.ts(2538) error message occurred

onClick() { let obj = { fName: "ali", LName: "sarabi", age: "19", } let fieldName = prompt("field"); alert(obj[fieldName]); } I encountered an issue with the code above where alert(obj[fieldName] ...

Expanding the StringConstructor in TypeScript results in a function that is not defined

I'm currently trying to enhance the String class in TypeScript 2.5 by adding a static method, which will be compiled to ES5. Here's what I have in StringExtensions.d.ts: declare interface StringConstructor { isNullOrEmpty(value: string | nu ...

Using a function to implement *ngFor results in generating a loop

When using *ngFor in Angular with a function that returns data, the function gets called multiple times and can sometimes result in a loop: app.component.ts export class AppComponent { getArray(): string[] { //I can track when this function is c ...

Header checkbox in expansion panel

I am facing an issue with the md-checkbox component when used as a title in the header of an expansion panel. The problem arises when I try to check the checkbox, causing the expansion panel to change its expanded state to false, preventing me from check ...

Error importing Firestore in Firebase Cloud Function

As I work on my cloud function, Firebase Firestore gets automatically imported in the following way: import * as functions from 'firebase-functions'; import { QuerySnapshot } from '@google-cloud/firestore'; const admin = require(&ap ...

The browser is initiating an HTTP request upon refreshing a webpage built with Angular

Hey there, currently I'm working on an Angular project that involves making API calls. I have the API URL set up as: const SERVER_URL = https://api.example.com Everything works smoothly until I reload the page after some successful API calls and th ...

Having trouble adding Bootstrap to Angular with Webpack? You might come across the error message: "File to import not found or unreadable: ../bootstrap/sc

I have decided to incorporate Bootstrap into my project. My attempt at installation involved using "bootstrap": "^4.0.0-alpha.5" I followed a tutorial found at https://github.com/AngularClass/angular2-webpack-starter/wiki/How-to-use-Bootstrap-4-and-Sass- ...

Potential explanation for unexpected Typescript initialization error

I am encountering the compiler error The property 'options' is not initialized or assigned in the constructor. However, upon reviewing the code for the respective class, it is clear that this reported error does not accurately reflect the actual ...

Enhance your React Native experience with IntelliSense recommending react-native/types over react-native

I am trying to bring in <View from react-native, but instead, I am getting react-native/types https://i.sstatic.net/FeRKT.png How can I resolve this issue? This is a new project starting from scratch and I followed the documentation by adding TypeScri ...

"Exploring the world of unit testing with Chutzpah and Jasmine in TypeScript

Currently, I am in the process of configuring Chutzpah and Jasmine to work together within visual studio. My main objective is to successfully run unit tests with TeamCity integration. Whenever I save my code, all TypeScript files are compiled into a sing ...

Angular 2 encounters issues with *ngFor functionality

I am currently experiencing some difficulties while trying to use *ngFor to access an array of objects in Angular 2. When I define the array like this: employees=[ {name:'a',age:'25'}, {name:'b',age:&apo ...

Issue with Click event not working on dynamically added button in Angular 8

My goal is to dynamically add and remove product images when a user clicks the add or delete button on the screen. However, I am encountering an issue where the function is not being called when dynamically injecting HTML and binding the click event. Below ...

Having trouble importing a file in TypeScript?

I needed to utilize a typescript function from another file, but I encountered an issue: I created a file called Module.ts with the following code snippet: export function CustomDirective(): ng.IDirective { var directive: ng.IDirective = <ng.IDire ...

Guide to releasing a NestJs library on npm using the nrwl/nx framework

Struggling with creating a publishable NestJS library using NX. Despite reading numerous documentations, I still can't figure it out. I've developed a NestJS library within an NX monorepository and now I want to publish just this library on NPM, ...

utilizing props to create a navigational link

How can I display a tsx component on a new tab and pass props into the new page? Essentially, I'm looking for the equivalent of this Flutter code: Navigator.push( context, MaterialPageRoute(builder: (context) => Page({title: example, desc: ...

No data being displayed or returned from API when using async await

My Ionic 6 + Angular 14 application is currently facing an issue with displaying data retrieved from an API... I have implemented a service to fetch the data from the API and then called this service in the component. The app compiles without any errors a ...

What is the recommended approach for returning two different types in a TypeScript function?

My API function currently performs a post request and returns an Observable of ModelAResponse, which is an interface I have defined. I now want to modify this function so that it can return an Observable of either ModelAResponse or ModelBResponse based on ...

Encountering the "Argument of type 'string' is not assignable to parameter of type 'never'" error when using Array.prototype.includes

The data type for keys is a combination of string[] | number[], which is derived from the ID type. The data type for id is simply ID. We want to check if the id exists within the array of keys. import React, { useState } from 'react'; type Distr ...