/** Angular Imports. */ import { Component , OnInit , Input } from '@angular/core' ; import { FormGroup , FormBuilder , Validators } from '@angular/forms' ; import { ActivatedRoute , Router } from '@angular/router' ; /** Custom Services. */ import { LoansService } from 'app/loans/loans.service' ; /**
 * Add Collateral component.
 */ @ Component ( { selector : 'mifosx-add-collateral' , templateUrl : './add-collateral.component.html' , styleUrls : [ './add-collateral.component.scss' ] } ) export class AddCollateralComponent implements OnInit { @ Input ( ) dataObject : any ; /** Collateral form. */ collateralForm : FormGroup ; /** Loan Id. */ loanId : string ; param { FormBuilder } formBuilder param { Router } router param { ActivatedRoute } route param { LoansService } LoansService constructor ( private formBuilder , private router , private route , private loanService ) { } ngOnInit ( ) { this . createAddCollateralForm ( ) ; } /**
     * Set Collateral form.
     */ createAddCollateralForm ( ) { this . collateralForm = this . formBuilder . group ( { 'collateralTypeId' : [ '' , Validators . required ] , 'value' : [ '' , Validators . required ] , 'description' : [ '' ] } ) ; } /**
     * Submits collateral form.
     */ submit ( ) { const collateralTypeId = this . collateralForm . value . collateralTypeId ; this . collateralForm . patchValue ( { 'collateralTypeId' : collateralTypeId } ) ; const loanId = this . route . parent . snapshot . params [ 'loanId' ] ; const collateralForm = this . collateralForm . value ; collateralForm . locale = 'en' ; this . loanService . createLoanCollateral ( loanId , collateralForm ) . subscribe ( ( response ) => { this . router . navigate ( [ '../../general' ] , { relativeTo : this . route } ) ; } ) ; } }