Custom component Interpolation

My Custom Component is:


<div *ngIf="!errorInput">
        {{ errorMessage }}


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

  selector: 'app-validate',
  templateUrl: './form-validate.component.html',
  styleUrls: ['./form-validate.component.css'],
export class FormValidateComponent implements OnInit {
  @Input() errorMessage: string;
  @Input() errorInput: boolean;

  constructor() {}

  ngOnInit(): void {}

I am using the above to validate the form and display the validation error message.

I am using this custom component as follows

<input type="text" formControlName="description" pInputText
    style="border-color: black;">

    [errorInput]="isValid('description', this.formGroup)"
    [errorMessage]="displayErrorMessage('description','Enter description', this.formGroup)">

isValid method validates based on the Validator and displayErrorMessage returns the error message.

This is working as expected.

In my requirement, I have to generate form groups and form fields dynamically, and validate the same.

I am able to create form groups, fields, and validators.

Form control name will get replace based on the dynamic values.

<div class="col-md-6"
    *ngFor="let attribute of attributeList; let attributeLength = count; let attributeCount = index;">

    <label> {{attribute.attributeName}}</label>

    <input type="text" formControlName="{{attribute.attributeName}}" pInputText
    style="border-color: black;">

    [errorInput]="isValid('{{attribute.attributeName}}', this.formGroup)"
    [errorMessage]="displayErrorMessage('{{attribute.attributeName}}','Enter as per validator ', this.formGroup)">

</div>                               ​

In this above code {{attribute.attributeName}} is getting replaced properly everywhere except in the following

    [errorInput]="isValid(**'{{attribute.attributeName}}'**, this.formGroup)"
    [errorMessage]="displayErrorMessage(**'{{attribute.attributeName}}'**,'Enter as per validator ', this.formGroup)">

If i log, the first parameter of isValid, i am getting {{attribute.attributeName}} instead of the actual value.

For the custom component, will it get replaced?

Can you please help me to resolve this?

Read more here:

Content Attribution

This content was originally published by user1862354 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: