Как включить один и тот же объект formBuilder в несколько компонентов? - PullRequest
0 голосов
/ 19 декабря 2018

Я создал объект Builder формы и хочу включить его в несколько других компонентов.Можно ли построить один и включить его в другие компоненты, используя сервис или любым другим способом?Мой объект огромен, и включение его в другие компоненты делает файл TS длинным.Я хочу уменьшить размер файла TS.Мой фб объект;

    `export class ApplicationComponent implements OnInit {

     applicationForm: FormGroup;
     constructor(private fb: FormBuilder, private route:Router, private activRoute:ActivatedRoute,
    private _ser: ApiServiceService) { 
    this.applicationForm = this.fb.group({
    //Application
      "IsNew": ['1'],
      "StudentID": ['', Validators.required,],
      "StudInfoID": [''],
      "UniversityID": [''],    // ?            
      "UniversityName": [''],  // ?      
      "CountryCode": [''],     // ?
      "DateOfApplication": ['', Validators.required,],
      "FirstName": [''],
      "MiddleName": [''],       // default null         
      "LastName": [''],
      "ApplicationStatusID": [''],    // ?           
      "Gender": [''],
      "DateOfBirth": [''],

    //personal Details                
      "PlaceOfBirth": [''],
      //Contact Details
      "EmailID": [''],
      "Handphone": [''],
      "Telephone": [''],
      "EmergencyContactName": [''],
      "EmergencyContactRelationShip": [''],
      "EmergencyContactTelephone": [''],
      //Address Details
      //Permanant Address
      "PermanentAddressCountryCode": [''],
      "permanentAddressState": [''],
      "PermanentAddressCity": [''],
      "PermanentAddress": [''],
      "PermanentAddressPostalCode": [''],
      //Mailing Address
      "MailingAddressCountryCode": [''],
      "MailingAddressState": [''],
      "MailingAddressCity": [''],
      "MailingAddress": [''],
      "MailingAddressPostalCode": [''],
      //Passport Details
      "PassportNumber": [''],
      "PassportIssueDate": [''],
      "PassportExpiryDate": [''],

    //Parent Details
      //Father Details
      "FatherFullName": [''],
      "FatherCitizenShip": [''],
      "FatherOccupation": [''],
      "FatherAddress": [''],
      "FatherPostalCode": [''],
      "FatherOfficeTelephone": [''],
      "FatherHomeTelephone": [''],
      "FatherHandPhone": [''],
      "FatherFaxNumber": [''],
      "FatherEmail": [''],
      //Mother Details             
      "MotherFullName": [''],
      "MotherCitizenShip": [''],
      "MotherOccupation": [''],
      "MotherAddress": [''],
      "MotherPostalCode": [''],
      "MotherOfficeTelephone": [''],
      "MotherHomeTelephone": [''],
      "MotherHandPhone": [''],
      "MotherFaxNumber": [''],
      "MotherEmail": [''],
      //Guardian Details
      "GuardianFullName": [''],
      "GuardianCitizenShip": [''],
      "GuardianOccupation": [''],
      "GuardianAddress": [''],
      "GuardianPostalCode": [''],
      "GuardianOfficeTelephone": [''],
      "GuardianHomeTelephone": [''],
      "GuardianHandPhone": [''],
      "GuardianFaxNumber": [''],
      "GuardianEmail": [''],

    //security questions
      "FirstSchoolName": [''],
      "MotherMedianName": [''],
      "FavoriteFood": [''],
      "FavoriteHoliday": [''],

    //medical disability needs
      "ChkmedicalconditionwhichmayaffectyourstudiesYes": [''],
      "ChkmedicalconditionwhichmayaffectyourstudiesNo": [''],
      "ChkHearing": [''],
      "ChkMedical": [''],
      "ChkVision": [''],
      "ChkMobility": [''],
      "ChkOther": [''],
      "Other": [''],
      "ChkWhatCICY": [''],
      "ChkWhatCICN": [''],

    //other Info
      "NationalServiceStatus": [''],
      "ORDDate": [''],
      "ExemptedReason": [''],
      "SpecialSkill": [''],
      "SpecialSkillExplain": [''],
      "ArrestedByPolice": [''],
      "ArrestedBypoliceExplain": [''],
      "DismissedFromEmployment": [''],
      "DismissedFromEmploymentExplain": [''],
      "MedicalCondition": [''],
      "MedicalConditionExplain": [''],
      "SubjectToSanction": [''],
      "SubjectToSanctionExplain": [''],
      "KnowAtSunrice": [''],
      "Source": [''],
      //co-curricular activities
      "DetailsOfECAMemberShip": [''],
      //English Language Proficiency
      "ChkEngLangFirstLanguageYes": [''],
      "ChkEngLangFirstLanguageNo": [''],
      "ChkIELTS": [''],
      "ChkTofel": [''],
      "ChkCute": [''],
      "ChkOtherEngLang": [''],
      "ChkGCEO": [''],
      "EngScoreGrade": [''],
      //sponsor details
      "ChktutionfeePaidByOrganisationY": [''],
      "ChktutionfeePaidByOrganisationN": [''],
      "OrganisationName": [''],
      "Status": [''],

    //Documents Required
      "ChkSPM": [''],
      "ChkALevelResult": [''],
      "ChkALevelCert": [''],
      "ChkDegreeResult": [''],
      "ChkDegreeCert": [''],
      "ChkPassportCopy": [''],
      "ChkReferenceLetter": [''],
      "ChkPersonalStatement": [''],
      "ChkIELTSResult": [''],
      "ChkCV": [''],
      "ChkPortfolio": [''],
      "ChkchkOthers": [''],

    // '?'               
      "DocumentsOthers": [''],
      "CreatedBy": [''],
      "UpdatedBy": [''],
      "CreatedDate": [''],
      "ModifiedDate": [''],
      "ApplicationNumber": [''],

    //new field 'parent-details'
      "fathersector": [''],
      "Mothersector": [''],
      "Gardiansector": [''],

    //for counselor '?'
      "EmpCode": [''],
      "Counsellor": ['', 
   [Validators.required,]],
      "CounsellorMobileNo": [''],

    //Children Details
      "FullName1": [''],
      "Ctizenship1": [''],
      "sex1": [''],
      "DateOfBirth1": [''],
      "countryofBirth1": [''],
      "placeofbirth1": [''],
      "FullName2": [''],
      "Ctizenship2": [''],
      "sex2": [''],
      "DateOfBirth2": [''],
      "countryofBirth2": [''],
      "placeofbirth2": [''],
      "FullName3": [''],
      "Ctizenship3": [''],
      "sex3": [''],
      "DateOfBirth3": [''],
      "countryofBirth3": [''],
      "placeofbirth3": [''],
      "FullName4": [''],
      "Ctizenship4": [''],
      "sex4": [''],
      "DateOfBirth4": [''],
      "countryofBirth4": [''],
      "placeofbirth4": [''],
      "FullName5": [''],
      "Ctizenship5": [''],
      "sex5": [''],
      "DateOfBirth5": [''],
      "countryofBirth5": [''],
      "placeofbirth5": [''],
      "FullName6": [''],
      "Ctizenship6": [''],
      "sex6": [''],
      "DateOfBirth6": [''],
      "countryofBirth6": [''],
      "placeofbirth6": [''],
      "Identity": [''],

    //Documents for under 18
      "chkguardianslip": [''],
      "chkhomestay": [''],
      "chkapprovedhostelaccomodation": [''],
      "chkwelfareform": [''],
      "chkCAAW": [''],
      "chkform1223": [''],
      "chkstudent": [''],
      "chkfather": [''],
      "chkmother": [''],
      "chkcourtletter": [''],
      "chkdeceasedletter": [''],
      "chkstudbirthcertificate": [''],
      "chkoyher1": [''],
      "txtother1": [''],

    // personal details
      "MaillingAddSameAsPermanat": [''], 
    //Address details

    //Application 
      "IC_No": ['', [Validators.required,]],
      "Counsellor2": [''],
      "EmpCode2": [''],
      "Counsellor3": [''],
      "EmpCode3": [''],

    // '?'
      "RejectedStatusRemarks": [''] 
    });
  }`

Я хочу включить этот объект в еще 8 компонентов.Есть ли способ написать этот объект где-нибудь еще и включить во все компоненты?

Спасибо

1 Ответ

0 голосов
/ 19 декабря 2018

Полагаю, вам нужна конфигурация FormGroup, которую вы можете использовать несколько раз.Я не пробовал, но, думаю, вы можете определить объект в отдельном файле .ts, например,

export formConfig: {[key: string]: any} = {

    //Application
      "IsNew": ['1'],
      "StudentID": ['', Validators.required,],
      "StudInfoID": [''],
      "UniversityID": [''],    // ?            
...
}

, а затем импортировать этот объект в ваш Component и передать его в FormBuilder 'Метод s .group.

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