0

I am new to angular 5, I have created an service for data

service.ts:

import { Injectable } from '@angular/core';
import { prmDataField } from '../_models/index'

 @Injectable()
 export class prmService {

    prmDataFields = [
new prmDataField('Training & Recruitment', 'expenses', 'billNo', 'totalAmt')];
 }

component.ts:

import { prmService } from '../data.service';
constructor(private prmDataLabel: prmService) {}

compontent.html

enter image description here

There are textbox under this head which are in service.ts, I want to load prmDataFields data to this textbox onload of page.

2 Answers 2

1

In your service:

getFields() {

  prmDataFields: any[] = [
    new prmDataField('Training & Recruitment', 'expenses', 'billNo', 'totalAmt')
  ];

  return prmDataFields;
}

In your component:

this.fields = this.prmDataLabel.getFields()

Template:

<div *ngFor="let field of fields"> ... </div>

Take a look at this demo from the Angular docs to get an idea of how dynamic forms should work. It would also be a good idea to read through the example for this demo as well.

Sign up to request clarification or add additional context in comments.

Comments

1

In your component you should define a variable to hold the prmDataFields:

prmDataFields = this.prmService.prmDataFields then

You loop through the array with ngFor to display wherever your text box is:

<div *ngFor="let dataField of prmDataFields">
    {{ dataField }}
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.