Получите данные в форму с Angular - PullRequest
0 голосов
/ 19 июня 2020

Я пытаюсь получить данные из серверной части в форму с angular. Я создал model.ts, service.ts и компонент формы, но в форме. html Я точно не знаю, как я вызываю данные. Я думаю, что мне следует использовать * ngModel, но я не знаю, как именно. вот мой код:

service.ts:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, Subject } from 'rxjs';
import { Repo } from '../models/repo-models';

@Injectable({
  providedIn: 'root'
})
export class RepoService {

  constructor(private http:HttpClient) { }

  readonly APIUrl = "http://localhost:54344/Repo/";

  getRepo(): Observable<Repo[]> {
    return this.http.get<Repo[]>(this.APIUrl + '/RepoId/82,2')
  }
}

form.ts ;

import { Component, OnInit } from '@angular/core';
import {NgForm} from '@angular/forms';
import { RepoService } from '../services/repo.service';
import { DecimalPipe } from '@angular/common';

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

rowData : any;
  constructor(public service: RepoService) { }

  getDropDownlist(){
    this.service.getRepo().subscribe(data => this.rowData = data);

    }

 ngOnInit(): void {
  }
}

и форма. html:

<div style="display:flex;" class="panel panel-default">
    <div style="width: 500px; height: 500px;"></div>
 <form   autocomplete="off" >
    <div class="form-group">
        <label>Folder</label>
        <input required type="text" id="folder"  placeholder="Enter a folder" name="Folder" style="width: 400px;">
      </div>



      <div class="form-group">
          <label >Type</label>
          <select required  id="Typee" name="Typee"  style="width: 200px;">
               <option>Loan</option>
              <option>Borrow</option>
            </select>
      </div>
      <div class="form-group" >

        <label >Cpty</label>
         <select required type="text"   id="isin" placeholder="Enter the Cpty" name="Cpty"  style="width: 400px;">
    <option>BNP</option>
    <option>SG</option>
         </select>  
      </div>
      <div class="form-group" >

        <label >Sec. ShortName</label>
         <input required type="text"   id="isin" placeholder="Enter the ShortName" name="secshortname"  style="width: 400px;">

      </div>
        <div class="form-group">
          <label >Trade Date</label>
          <input readonly   id="Trade" name="Trade_date"   style="width: 400px;">
        </div>

        <div class="form-group">
          <label >Start Date</label>
          <input required type="date"  id="Start" name="Start_date"  style="width: 400px;" >

        </div>

        <div class="form-group">
          <label >Quantity</label>
          <input required type="number"  id="Quantity"  placeholder="Enter the Quantity" name="quantity"  style="width: 400px;">
        </div>

        <div class="form-group">
          <label >Gross Amount</label>
          <input required type="number"  id="Price"  placeholder="Enter the Gross Amount" name="Price"  style="width: 400px;">
          <select type="text">
            <option>EUR</option>
            <option>GBP</option>
            <option>JPY</option>

          </select>
        </div>

    </form>

Я очень признателен за вашу помощь. Хорошего дня :)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...