Angular 用字符串插值预填充角度反应形式

Angular 用字符串插值预填充角度反应形式,angular,forms,angular-reactive-forms,Angular,Forms,Angular Reactive Forms,是否有可能用另一个组件的值预填充反应式表单 import { Component, OnInit } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; import { Location } from '@angular/common'; import { FormGroup, FormControl, FormArray, Validators} from '@angular/for

是否有可能用另一个组件的值预填充反应式表单

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

import { Location } from '@angular/common';
import { FormGroup, FormControl, FormArray, Validators} from '@angular/forms';
import { DatePicker } from 'angular2-datetimepicker';

import { PacService } from '../../../services/pacient.service';
import { PsmService } from '../../../services/psm.service';

import { Pacient } from '../../Pacienti-Main/pacient';

//EXPORTURI
export interface Pilon {
  value: string;
  viewValue: string;
}
export interface PozitieSchema {
  value: string;
  viewValue: string;
}
export interface Flacon {
  value: string;
  viewValue: string;
}

@Component({
  selector: 'app-add-vizita',
  templateUrl: './add-vizita.component.html',
  styleUrls: ['./add-vizita.component.css']
})
export class AddVizitaComponent implements OnInit {

  vizitaForm: FormGroup;

  pacienti: any;
  pacient: Pacient;
  psms:any;
  responsabili: any;
  responsabil: any;

  date: Date = new Date();
  settings = {
      bigBanner: false,
      timePicker: false,
      format: 'dd-MM-yyyy',
      defaultOpen: false
  }

  //Piloni
  piloni: Pilon[] = [
    {value: 'Pilon-1', viewValue: 'Pilon 1'},
    {value: 'Pilon-2', viewValue: 'Pilon 2'},
  ];
  //PozitieSchema
  pozitii: PozitieSchema[] = [
    {value: 'In Tratament', viewValue: 'In Tratament'},
    {value: 'In Pauza', viewValue: 'In Pauza'},
    {value: 'Intrerupere', viewValue: 'Intrerupere'},
  ]
  modFlacon: Flacon[] = [
    {value: 'Valid', viewValue: 'Valid'},
    {value: 'Invalid', viewValue: 'Invalid'},
  ]
  grConfort: string[] = ['1', '2', '3', '4', '5'];
  grDurere: string[] = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'];
  ea: string[] = ['Da', 'Nu'];


  constructor( private router: Router, private _pacService: PacService, private psmService: PsmService, private route: ActivatedRoute, private location: Location) {
    DatePicker.prototype.ngOnInit = function() {
      this.settings = Object.assign(this.defaultSettings, this.settings);
      if (this.settings.defaultOpen) {
      this.popover = true;
      }
      this.date = new Date();
      }; 
   }

  ngOnInit() {
    this.getPatients();
    this.getSinglePatient();
   }

   this.vizitaForm = new FormGroup({
    Name: new FormControl(`${this.pacient.Name}`), // this line should be populated with the name of the patient.
    _id_pacient: new FormControl(''),
    Adresa: new FormControl(''),
    Judet: new FormControl(''),
    DataVizita: new FormControl(''),
    DataStartTratamentCurent: new FormControl(''),
    Pilon: new FormControl(''),
    VizitaUrmatoare: new FormControl(''),
    PSM: new FormControl(''),
    MedicCurant: new FormControl(''),
    IntreruperePermanenta: new FormControl(''),
    RidicareMedic: new FormControl(''),
    PrezentareFarma: new FormControl(''),
    RidicareFarma: new FormControl(''),
    Responsabil: new FormControl(''),
    ZileAsteptare: new FormControl(''),
    PozitieSchema: new FormControl(''),
    PozitieZi: new FormControl(''),
    Flacon: new FormControl(''),
    NrPastile: new FormControl(''),
    TratamentPrecedentB: new FormControl(''),
    GrConfort: new FormControl(''),
    GrDurere: new FormControl(''),
    EA: new FormControl(''),
    Observatii: new FormControl(''),
    GPS: new FormControl(''),


   })

  }


 addVisit(visitForm){
   this._pacService
   .addVisit(this.visitForm.value)
   .subscribe(() => this.goBack())
 }

  getPacienti() {
    this._pacService
      .getPacienti()
      .subscribe(pacienti => {
        this.pacienti = pacienti;
      })
  }


  getSinglePacient(){
    var id = this.route.snapshot.params['id'];
    this._pacService
      .getPacient(id)
      .subscribe(patient => {
        this.patient = patient[0]
      });
  }



  goBack() {
    this.location.back(); // <-- go back to previous location on cancel
  }
从'@angular/core'导入{Component,OnInit};
从'@angular/Router'导入{Router,ActivatedRoute};
从“@angular/common”导入{Location};
从“@angular/forms”导入{FormGroup、FormControl、FormArray、Validators};
从'angular2 datetimepicker'导入{DatePicker};
从“../../../services/pacient.service”导入{PacService};
从“../../../services/psm.service”导入{PsmService};
从“../../Pacienti Main/Pacient”导入{Pacient};
//EXPORTURI
导出接口Pilon{
值:字符串;
viewValue:字符串;
}
导出接口PozitieSchema{
值:字符串;
viewValue:字符串;
}
导出接口Flacon{
值:字符串;
viewValue:字符串;
}
@组成部分({
选择器:“应用程序添加vizita”,
templateUrl:'./add vizita.component.html',
样式URL:['./添加vizita.component.css']
})
导出类AddVizitaComponent实现OnInit{
vizitaForm:FormGroup;
帕森蒂:任何;
和平:和平;
psms:任何;
责任:任何;
责任:任何;
日期:日期=新日期();
设置={
大旗:错,
计时器选择器:错误,
格式:“dd-MM-yyyy”,
defaultOpen:false
}
//皮洛尼
piloni:Pilon[]=[
{value:'Pilon-1',viewValue:'Pilon 1'},
{value:'Pilon-2',viewValue:'Pilon 2'},
];
//波兹提谢马
pozitii:PozitieSchema[]=[
{value:'In tradament',viewValue:'In tradament'},
{value:'In Pauza',viewValue:'In Pauza'},
{value:'Intrerupere',viewValue:'Intrerupere'},
]
modFlacon:Flacon[]=[
{value:'Valid',viewValue:'Valid'},
{value:'Invalid',viewValue:'Invalid'},
]
grConfort:string[]=['1','2','3','4','5'];
grDurere:string[]=['1','2','3','4','5','6','7','8','9','10'];
ea:string[]=['Da','Nu'];
构造函数(专用路由器:路由器,专用_pacService:pacService,专用psmsservice:psmsservice,专用路由:ActivatedRoute,专用位置:location){
DatePicker.prototype.ngOnInit=函数(){
this.settings=Object.assign(this.defaultSettings,this.settings);
if(this.settings.defaultOpen){
this.popover=true;
}
this.date=新日期();
}; 
}
恩戈尼尼特(){
这个。getPatients();
这个.getSinglePatient();
}
this.vizitaForm=新表单组({
Name:newformcontrol(`this.pacient.Name}`),//此行应填充患者的姓名。
_id权限:新表单控件(“”),
Adresa:新表单控件(“”),
朱迪特:新表单控件(“”),
DataVizita:新表单控件(“”),
DataStartStratmentCurrent:新表单控件(“”),
Pilon:新表单控件(“”),
VizitaUrmatoare:新表单控件(“”),
PSM:新表单控件(“”),
MedicCurant:新表单控件(“”),
IntreSuperPermanentA:新窗体控件(“”),
新表单控件(“”),
PrezentareFarma:新表单控件(“”),
RidicareFarma:新表单控件(“”),
责任:新表单控制(“”),
ZilesTeptare:新表单控件(“”),
PozitieSchema:new FormControl(“”),
PozitieZi:新表单控件(“”),
Flacon:新表单控件(“”),
NrPastile:新表单控件(“”),
TratamentPreventB:新表单控件(“”),
GrConfort:新表单控件(“”),
GrDurere:新表单控件(“”),
EA:新表单控件(“”),
观察二:新的FormControl(“”),
GPS:新的FormControl(“”),
})
}
addVisit(visitForm){
这是我们的服务
.addVisit(this.visitForm.value)
.subscribe(()=>this.goBack())
}
getPacienti(){
这是我们的服务
.getPacienti()
.订阅(pacienti=>{
this.pacienti=pacienti;
})
}
getSinglePacient(){
var id=this.route.snapshot.params['id'];
这是我们的服务
.getPacient(id)
.订阅(患者=>{
this.patient=patient[0]
});
}
戈巴克(){

this.location.back();//您可以尝试使用
新表单控件(patient.Name)


你有没有理由不直接执行
新建表单控件(patient.Name)
?如果我执行新建表单控件(patient.Name),它将只保存在数据库中patient.Name,而不是像Bob或Kevin那样的值…你需要确保
patient.Name
周围没有引号,它们不是…:(这应该是一件容易的事。在我的html中,每件事都可以,但它不带值…你能不能用你的问题来说明你在哪里尝试使用了
患者.Name
请?另外,这是否在你的
.ts
文件中?
<form [formGroup]="vizitaForm" (ngSubmit)="addVizita(vizitaForm)">

     <!--IDENTIFICARE-->
     <h6 class="alert alert-dark">Identificare</h6>
     <div class="row" style="margin-top:10px; margin-bottom: 10px">
         <div class="col-md-3 col-sm-12 col-xs-12">
             <mat-card>
                 <label>Pacient<b><span class="text-danger">*</span></b></label><br>

                 <mat-form-field class="example-full-width">
                    <input matInput placeholder="{{patient.Nume}}" formControlName="Name">
                  </mat-form-field>
this.visitForm = new FormGroup({
  PatientName: new FormControl(patient.Name),
  _id_pacient: new FormControl(patiet._id),
  Adress: new FormControl(patient.Adress),