Content not displaying in Angular Material Tab (mat-tab)

Incorporating Angular Material tabs into my Angular 5 project has been quite the challenge. I am attempting to use the tabs as a submenu on a links page, where numerous links are categorized into smaller sections that will be displayed when selected from the tab group.

To display each tab, I have implemented an ngFor loop and structured the set of links within an unordered list using another ngFor loop. However, despite the tab group functioning correctly, the list of links fails to appear.

After researching similar issues, it seems that most were resolved by adding the BrowserAnimationsModule, which I already have imported into my project.

Here is the HTML code snippet:

<mat-tab-group>
    <mat-tab *ngFor="let tab of linkMenu" label="{{tab.dispName}}">
        <div class="tab-content">
            <ul>
                <li *ngFor="let link of tab.varName"><a href="link.url">{{link.name}}</a></li>
            </ul>
        </div>
    </mat-tab>
</mat-tab-group>

And here is the associated TypeScript code:

import { Component, OnInit } from '@angular/core';

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

    linkMenu = [
        {dispName: "Link Set A", varName: "linksA"},
        {dispName: "Link Set B", varName: "linksB"},
        {dispName: "Link Set C", varName: "linksC"},
        {dispName: "Link Set D", varName: "linksD"},
    ]

    linksA = [
        {name: "foo1",url: ""},
        {name: "bar1",url: ""},
        {name: "spam1",url: ""},
        {name: "eggs1",url: ""}
    ]

    linksB = [
        {name: "foo2",url: ""},
        {name: "bar2",url: ""},
        {name: "spam2",url: ""},
        {name: "eggs2",url: ""}
    ]

    linksC = [
        {name: "foo3",url: ""},
        {name: "bar3",url: ""},
        {name: "spam3",url: ""},
        {name: "eggs3",url: ""}
    ]

    linksD = [
        {name: "foo4",url: ""},
        {name: "bar4",url: ""},
        {name: "spam4",url: ""},
        {name: "eggs4",url: ""}
    ]

    constructor() { }

    ngOnInit() {
    }

}

Answer №1

Make sure to pass arrays into your linkMenu[], not strings. The linksMenu[] should be declared last, after linksA-D.

linkMenu = [
        {dispName: "Link Set A", varName: this.linksA},
        {dispName: "Link Set B", varName: this.linksB},
        {dispName: "Link Set C", varName: this.linksC},
        {dispName: "Link Set D", varName: this.linksD},
    ]

To see a working example of your code, check out the StackBlitz demo below.

StackBlitz Demo

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

When attempting to parse the request body in a POST request using Koa on Firebase Cloud Functions, the request hangs and times out

I am currently developing a small website and hosting static files using Firebase Hosting (FH). All requests are being redirected to a single function on Firebase Cloud Functions (FCF), where I am utilizing Koa framework with koa-router to handle the reque ...

Generating a dynamic clickable div using Angular 6

How can I create a user-friendly interface that displays an image with clickable divs around detected faces, allowing users to view specific attributes for each face? I'm looking for a solution where I can have divs or buttons around each face that t ...

Access your Angular 2 application on an external device during the development process

Is there a way to view your app in an external device like a cell phone web browser, instead of just running npm start and viewing it in your desktop browser? ...

Angular 4 ngbtypeahead search filter

I am looking for a way to remove previous results from ngbtypeahead if the user does not select an option. Even when all characters are removed from the input text, the results should not be displayed. NgbdTypeaheadHttp.component.ts export class NgbdType ...

A guide to updating directives on the fly in Angular 2

Currently, I am using Angular 2+ along with Material 2. In my project, I have a few md-button elements that I need to dynamically change to md-raised-button. To clarify, this is what I aim to do: <a md-button [routerLink]="['/home']">Hom ...

Having constant problems with ngModel twoway binding. Any suggestions on how to successfully bind to a property in order to update an api link?

I am attempting to implement two-way binding in order to dynamically change the API endpoint when a button is clicked. The value attribute of the button should be used as part of the API URL string. I tried following an example in the Hero Angular App, bu ...

Challenge encountered when utilizing angular 2 RC router for programmatic route navigation

Currently, I am utilizing the RC router in version rc1 with two defined routes as shown below: @Routes([ {path: '/', component: HomeComponent}, {path: '/signin', component: SigninComponent}, {path: '/dashboard', c ...

TypeScript is encountering difficulty locating a node module containing the index.d.ts file

When attempting to utilize EventEmitter3, I am using the following syntax: import EventEmitter from 'eventemitter3' The module is installed in the ./node_modules directory. It contains an index.d.ts file, so it should be recognized by Typescrip ...

Transforming FormData string key names into a Json Object that is easily accessible

Recently, I encountered an issue where my frontend (JS) was sending a request to my backend (Node Typescript) using FormData, which included images. Here is an example of how the data was being sent: https://i.stack.imgur.com/5uARo.png Upon logging the r ...

ReactJS Tutorial: Simple Guide to Updating Array State Data

const [rowData, setRowData] = useState([]); const old = {id: 'stud1', name: 'jake', room: '2'}; const newData = {name: 'jake', room: '3A'}; useEffect(() => { let ignore = false; ...

Find your way to a designated location on a fluid Angular 2 webpage

Imagine I'm on a webpage where several items are displayed using *ngFor. Each item has a link that takes me to a different page when clicked. However, when I return to the original page using the back button, I'd like to be scrolled back to the s ...

What is the best way to customize a React component using TypeScript?

Let's say I have a functional component like this: function MyComp({a, b, c, d, e, f}: any) { ... } Is there a way to create a specialized version of this component where I provide values for "a" and "b," but allow other users to choose the r ...

Ensuring that the field is empty is acceptable as long as the validators are configured to enforce

I have successfully created a form using control forms. idAnnuaire: new FormControl('',[Validators.minLength(6),Validators.maxLength(6)]), However, I am facing an issue where when the field is left empty, {{form.controls.idAnnuaire.valid }} is ...

Transform the data received from the server into a TypeScript object

I'm facing a challenge in converting an object retrieved from the server to a TypeScript class I've created. While my TypeScript object has identical properties to the one returned by the server, the difference lies in the casing of the property ...

Setting up validators for an entire FormGroup in Angular ReactiveForms can be achieved by iterating through the

In my current project, I am dealing with a complex form that includes multiple fields. For each field, I have implemented various validators to ensure data integrity. For example, for the 'surname' field, I have the following validators: this.s ...

Testing an angular function that requires multiple arguments in its constructor

My goal is to conduct unit tests on functions within a component. The constructor for this component requires four arguments. Initially, I attempted to simply set the arguments as (new AClass, new BClass, new CClass, new DClass); however, some of these cla ...

The Angular Material nested Stepper's label position is being forcefully changed

When dealing with a nested Angular Material Stepper, the label position in the child stepper (labelPosition="end") may be overridden by the label position set in the parent stepper (labelPosition="bottom"). Check out the code snippet be ...

When attempting to execute my script, I encountered an error message stating that "TypeError: puppeteer.use(...) is not

Here is the current code that I've been working on. After switching it to a new folder, I encountered an error that wasn't present before. I made sure to reinstall all the necessary modules in the package.json file, but the issue persists. Is the ...

Can you retrieve the Angular Service Instance beyond the scope of an angular component?

Is it possible to obtain the reference of an Injectable Angular service within a generic class without including it in the constructor? I am exploring different methods to access the Service reference. For example: export class Utils { getData(): string ...

How Typescript allows variables to act as references to other variables

Imagine having a component with aliases for user data. This approach allows for shorter and cleaner variable names, making the code easier to read: @Component({ selector: 'my-view', templateUrl: './view.component.html', sty ...