Contrast the different characteristics of string dynamic arrays in Angular 6

I am working with two arrays of strings. One array is a dynamic list of checkboxes and the other is the source to check if the item exists in the first array. I need to implement this dynamically using Angular 6, can you help me with this?

Currently, the list of checkboxes needs to be updated dynamically based on certain conditions...

<div *ngFor="let p of people">
      <mat-checkbox class="example-margin secondary-text"
        [checked]="false" >p</mat-checkbox>
 </div>

Answer №1

If you want to verify the presence of items in both arrays, you can utilize a method like the one below, assuming that the arrays are string arrays as per your mention.

// Template
<div *ngFor="let p of people">
  <mat-checkbox class="example-margin secondary-text"
    [checked]="isInOtherArray(p)" >p</mat-checkbox>
</div>

// Component Method
public isInOtherArray(person) {

   return this.otherArray.indexOf(person) > -1;
}

Alternatively, you can directly implement it in your template:

<div *ngFor="let p of people">
  <mat-checkbox class="example-margin secondary-text"
    [checked]="otherArray.indexOf(p) > -1" >p</mat-checkbox>
</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

Can someone help me figure out how to add a new key value pair to an array in PHP?

Despite the abundance of documentation, I struggled to locate this one line of code in a 4000-line file. Accuracy is key on the first attempt. file_put_contents($myFile,serialize(array($email_number,$email_address))) or die("can't open file"); if ...

Verify if two items possess identical property values

There are 2 items: 1. obj1 = { bookRetail: 14.99, hierarchyDescription: "GUYS DENIM PANTS [ 0151 ]", isSelected: true, isAvailableInPivot: "Y", style: "VICE NWH NAVY WHITE DC [ M450MBON ]"} 2. obj2 = { bookRetail: 14.99, hier ...

The error page is requesting a root-layout, which indicates that having multiple root layouts is not feasible

My issue is as follows: The not-found page located in my app directory requires a root-layout which I have added to the same directory. However, this setup prevents me from using multiple root layouts in the structure below. How can I resolve this? It see ...

Resizing cell height in an HTML table is not supported by Angular 5

In my angular application, I've implemented a component that represents a basic HTML table. However, I'm facing an issue with reducing the height of cells within the table. It seems like my CSS styling is not affecting the display as desired. He ...

What is the process for eliminating the perplexing "default" attribute that has been inserted into JSON?

I recently came across the jsondata.json file: { "name": "John", "age": 30, "car": "ferrari" } Located in the same directory is a typescript file called main.ts where I simply output the json data using console.log import * as j from '. ...

Incorporate text/sentences from a file into a collection of strings in C

Being a novice programmer, currently enrolled in university, I have been assigned the task of creating a text-based adventure game in less than 2 months of studying programming. The requirement is that the game's text should be stored in a file. Init ...

Using ag-Grid's cellEditor with object values for selection

Looking to choose a user from a list of users: User.ts export class User { constructor (public id: number, public userName : string){} } The column definition appears as follows: this.columns = [ {headerName: "Assigned", field:"user ...

Merging an unspecified number of observables in Rxjs

My latest project involves creating a custom loader for @ngx-translate. The loader is designed to fetch multiple JSON translation files from a specific directory based on the chosen language. Currently, I am implementing file loading through an index.json ...

Sharing an angular app URL containing query parameters with multiple users

I am in need of a feature that allows me to transfer the filter settings on a page to another user. For instance, if I apply certain filters on a specific page, I would like to share the URL with those filters already applied to other users. ...

Is there a way to verify in Angular whether an image link has a width and height exceeding 1000?

I'm currently working on a function that checks if an image linked in an input field has a width and height greater than 1000 pixels, and is in JPG format. Here's my approach: HTML: <input (change)="checkValidImage(1, product.main_photo)" [ ...

Invalid Redux store: Element type is not valid; a string type is expected

I am running into an issue while setting up the redux store with typescript for the first time. The error message I am encountering is: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) ...

Retrieve the Document ID from Firebase

I'm currently exploring the functionality of Firebase and enhancing my workflow with "react-firebase-hooks". Is there a way for me to retrieve both the doc id and doc data simultaneously and pass them as props? Currently, I am only able to access the ...

"Frustrating issue with Firebase-admin dependency farmhash-modern resulting in webassembly error

Facing an issue while setting up firebase-admin SDK on my nextjs + TS project. Every time I try to call a SDK function, I encounter a webAssembly error. Specifically, when trying to configure a middleware for the server-side API and calling the verifyIdTok ...

Troubleshooting notifications generated by react-hook-form and zod

My customer registration form is causing all my error messages to show as "required." I suspect it might be a misconfiguration in zod or react-hook-form. Below, you'll find the code snippets. This is my generic input component: import { DetailedHTMLP ...

Discovering the total of elements in specific locations within two arrays

Hey there! I have a question that I need help with. Given arrays A and B containing natural numbers in incremental order, along with an arbitrary natural number K, how can we efficiently find all index pairs (i, j) where the sum of elements at those indexe ...

After compiling the code, a mysterious TypeScript error pops up out of nowhere, despite no errors being

Currently, I am delving into the world of TypeScript and below you can find the code that I have been working on: const addNumbers = (a: number, b: number) => { return a + b } Before compiling the file using the command -> tsc index.ts, the ...

What is the TypeScript definition for the return type of a Reselect function in Redux?

Has anyone been able to specify the return type of the createSelector function in Redux's Reselect library? I didn't find any information on this in the official documentation: https://github.com/reduxjs/reselect#q-are-there-typescript-typings ...

Setting an attribute on a custom component that is dynamically created within an Angular application

I am working with a custom library component called <my-icon>. To display the icon, I need to specify the property [name] like this: <my-icon [name]='warning'></my-icon> Currently, I am dynamically creating these icons in Type ...

Steps to obtain the download URL from AngularFireStorage after uploading the file using the getDownloadUrl() method

After successfully uploading images into my firebase storage, I want to retrieve the downloadURL and add it to my firestore database. When console logging "url", I am able to see the desired link. However, I am facing difficulties in using it. When attemp ...

Running nestjs-console commands within an Angular/nx workspace environment can be easily achieved by following these steps

I have integrated a NestJS application within an Angular / Nx workspace environment. For running commands in the Nest application, I am utilizing nestjs-console (e.g., to load fixture data). As per the instructions in the nestjs-console documentation, th ...