Angular8 Material Grid displaying headers and tiles, experiencing slight resizing issue with mat-grid-tile content

Exploring Angular8 Material: Grid Layout with Headers and Tiles

Currently, I am delving into the workings of the grid system within Angular Material. I am dynamically fetching components and organizing them within a grid. While the grid list and tiles are functioning as expected, there seems to be an issue with the content within the tiles, particularly the mat-figure section. It appears as though they are not fully acknowledging their placement within the tiles.

For instance, when the page is resized, the grid tiles adapt responsively and resize accordingly, but the content inside the tiles seems to overflow their boundaries. Additionally, the font sizes do not adjust as expected. While I could potentially address this with CSS, I am keen on understanding why the grid-list functionality is not working as intended.

I have included some screenshots for reference. One depicts the grid with a smaller screen resolution, showcasing the font size issue, and the other illustrates the rendering in the console.

https://i.sstatic.net/KyLZj.png

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

export interface ITile {
  color: string;
  cols: number;
  headerText: string;
  rows: number;
  text: string;
  componentName: string;
}

@Component({
  selector: 'app-forms',
  templateUrl: 'forms.component.html',
  styleUrls: ['forms.component.scss']
})
export class FormsComponent implements OnInit {
  tiles: Array<ITile>

  setComponents() {
    this.tiles = new Array<ITile>
    let components = [];
    components.push('autocomplete');
    components.push('checkbox');
    components.push('datepicker');
    components.push('formfield');
    components.push('input');
    components.push('radiobutton');
    components.push('select');
    components.push('slider');
    components.push('slidetoggle');
    console.log(components);

    components.forEach(component => {
      if (component === 'autocomplete') {
        const headerText = 'Auto Complete';
        this.setTile('#ccc', 4, headerText, 'example', 1, component);
      }
      if (component === 'checkbox') {
        const headerText = 'Checkbox';
        this.setTile('#ccc', 4, headerText, 'example', 1, component);
      }
      // Add more conditions for other components
    });
  }

  setTile(color: string, cols: number, headerText: string, text: string, rows: number, componentName: string) {
    const tile = {
      color,
      cols,
      headerText,
      text,
      rows,
      componentName
    };

    this.tiles.push(tile);
    console.log(JSON.stringify(this.tiles));
  }

  ngOnInit(): void {
this.setComponents();
  }
}
<mat-grid-list cols="4" rowHeight="1:1" gutterSize="55px">

  <mat-grid-tile class="grid-tile"
                 [colspan]="2"
                 [rowspan]="1"
                 *ngFor="let tile of tiles"
                 [colspan]="tile.cols"
                 [rowspan]="tile.rows"
                 [style.background]="tile.color">
    {{tile.text}}
    <app-checkbox *ngIf="tile.componentName === 'checkbox'"></app-checkbox>

    <app-autocomplete *ngIf="tile.componentName === 'autocomplete'"></app-autocomplete>
    <app-checkbox *ngIf="tile.componentName === 'checkbox'"></app-checkbox>

    <app-datepicker *ngIf="tile.componentName === 'datepicker'"></app-datepicker>
    <app-formfield *ngIf="tile.componentName === 'formfield'"></app-formfield>

    <app-input *ngIf="tile.componentName === 'input'"></app-input>
    <app-radiobutton *ngIf="tile.componentName ==='radiobutton'"></app-radiobutton>

    <app-select *ngIf="tile.componentName === 'select'"></app-select>
    <app-slider *ngIf="tile.componentName ==='slider'"></app-slider>

    <app-sidetoggle *ngIf="tile.componentName === 'slidetoggle'"></app-sidetoggle>
    <div style="width: 230px;"></div>

    <mat-grid-tile-header>
      <h3> {{tile.headerText}} </h3>
    </mat-grid-tile-header>
  </mat-grid-tile>
</mat-grid-list>

Answer №1

I encountered the same issue and decided to switch from the material grid to the angular flex grid. Check out this angular flex grid demo for more information.

You can implement this layout grid in your project:

  <div class="parent flex-card-height" fxLayout="row" fxLayout.sm="column" fxLayout.xs="column" fxLayoutGap="32px" fxFill>
    <mat-card fxFlex="50%" fxFill>
      <div class="mat-card-title heading"></div>
      <div class="left"
           *ngFor="let tile of tiles">
        {{tile.text}}
        <app-autocomplete *ngIf="tile.componentName === 'autocomplete'" class="spacing"></app-autocomplete>
      </div>
    </mat-card>

    <mat-card fxFlex="50%" fxFill>
      <div class="mat-card-title heading"></div>
      <div class="right"
           *ngFor="let tile of tiles">
        {{tile.text}}
        <app-checkbox *ngIf="tile.componentName === 'checkbox'" class="spacing"></app-checkbox>
      </div>
    </mat-card>
  </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

The type 'Observable<boolean>' cannot be assigned to type 'Observable<UserRegistration>'

function completeRegistration(email: string, password: string, firstName: string, lastName: string, location: string): Observable<UserDetails> { let body = JSON.stringify({ email, password, firstName, lastName,location }); let headers = new H ...

Moving information from two modules to the service (Angular 2)

Recently in my Angular2 project, I created two components (users.component and tasks.component) that need to pass data to a service for processing before sending it to the parent component. Code snippet from users.component.ts: Import { Component } fro ...

Why isn't the customer's name a part of the CFCustomerDetails class?

Currently, I am utilizing the cashfree-pg-sdk-nodejs SDK to integrate Cashfree payment gateway into my application. Upon examining their source code, I noticed that the CFCustomerDetails class does not include the customerName attribute. https://i.stack.i ...

Is there a way to verify the presence of data returned by an API?

I am trying to implement a system in my Index.vue where I need to check if my API request returns any data from the fetchData function. Once the data is fetched, I want to return either a boolean value or something else to my Index.vue. Additionally, I wou ...

Error TS7053 occurs when an element is given an 'any' type because a 'string' expression is being used to index an 'Object' type

When attempting to post data directly using templateDrivenForm and retrieve data from Firebase, I encountered the following type error message. Here are the relevant parts of my code: // Posting data directly using submitButton from templateDrivenForm onC ...

"Activate the mat-checkbox based on the outcome of a certain process

I'm working with a mat-checkbox that triggers a mat-dialog when clicked. If the user clicks "confirm" in the dialog, I want the checkbox to be checked. If they click "cancel", I want it to remain unchecked. How can I achieve this? Below is the method ...

The function, stored as state within a context provider, is experiencing only one update

I am facing an issue with my Next.js and Typescript setup, but I believe the problem is more general and related to React. Despite extensive research on Stack Overflow, I have not come across a similar problem. To provide some context: I have a <Grid&g ...

When evaluating code with eval, properties of undefined cannot be set, but the process works seamlessly without

Currently, I am attempting to utilize the eval() function to dynamically update a variable that must be accessed by path in the format myArray[0][0[1][0].... Strangely enough, when I try this approach, I encounter the following error: Uncaught TypeError: ...

Struggling with the compilation of this Typescript code

Encountering a compile error: error TS2339: Property 'waitForElementVisible' does not exist on type 'signinPage' SigninPage code snippet: export class signinPage{ constructor(){ emailInput: { selector: 'input[type ...

cycle through options of radio buttons

How can I display items of radio buttons, with the values of these items coming from a backend api? <div class="input-group col-md-9 input-group-sm"> <label>gender</label> </div> <!-- TO CORRECT ...

Is there a way to conceal an element within a component based on the current component being used with the router?

I have managed to hide an entire component, but I am unsure of how to show or hide specific elements within a component. export class AppComponent { headerFooterVisible: boolean; constructor(private router: Router) { router.events.subscribe(e =&g ...

Issue when calling .create() method on Mongoose schema: "this expression is not callable" error in TypeScript

Encountering an error with the .create method on a mongoose model in Next JS while making a call in an API route. The get request is functioning properly... The structure: pages>API>task.tsx import dbConnect from "../../util/dbconnect"; im ...

The new data is not being fetched before *ngFor is updating

In the process of developing a "Meeting List" feature that allows users to create new meetings and join existing ones. My technology stack includes: FrontEnd: Angular API: Firebase Cloud Functions DB: Firebase realtime DB To display the list of meeting ...

Why are my values not being applied to the model class in Angular 7?

I'm currently developing an online shopping website where I have defined my order Model class as shown below: import { User } from './user.model'; export class Order { constructor(){} amount: Number = 0; status: String = ""; date: ...

The Typescript Select is displaying an incorrect value

Here's the code snippet I've been working with: <select #C (change)="changeSelect(zone.id, C.value)"> <option *ngFor="let town of townsLocal" [attr.value]="town.data" [attr.selected]="town.data === zone.town && 'selected& ...

How to extract a type from a nested type using TypeScript

I am trying to define a type structure where both a and foo are optional: type Something = { a?: { foo?: { bar: { c: { id: string, countryCode: number, animal: { ... } } } } } } Now I n ...

Handling errors in nested asynchronous functions in an express.js environment

I am currently developing a microservice that sends messages to users for phone number verification. My focus is on the part of the microservice where sending a message with the correct verification code will trigger the addition of the user's phone n ...

Struggling to launch on Vercel and encountering the error message, """is not allowed by Access-Control-Allow-Origin. Status code: 204""

Greetings! I trust you are doing well. Currently, I am engrossed in developing a full-stack application. The app runs smoothly on localhost without any issues. However, upon deploying both the server and front end on Vercel, a snag arose when attempting to ...

The softAssert method is not available when trying to implement soft assertions within a TypeScript-based Protractor framework

Uncaught TypeError: assertion.softAssert is not a function I recently included a package called soft-assert using npm in my project. To install this package, I executed the following command: npm i soft-assert -g --save-dev Incorporated the following co ...

The upcoming development does not involve creating an entire HTML webpage using on-demand static site generation (SS

I’m encountering a problem when utilizing getStaticPaths and getStaticProps to create an on-demand SSG for a sharing page. My setup involves Next v12.1.0 and React 17.0.2. After building a specific /[id] page, I can retrieve the data but the HTML output ...