File
Implements
Index
Properties
|
|
Methods
|
|
Inputs
|
|
Methods
changeBirthYear
|
changeBirthYear(year)
|
|
|
initiateYearSelector
|
initiateYearSelector()
|
|
|
submitYearOfBirth
|
submitYearOfBirth()
|
|
|
birthYearOptions
|
Type : Array<number>
|
Default value : []
|
|
selectedYearOfBirth
|
Type : number
|
|
showYearOfBirthPopup
|
Default value : false
|
|
import { Component, Input, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ProfileService } from '@sunbird/profile';
import { ConfigService, ResourceService } from '@sunbird/shared';
import * as _ from 'lodash-es';
@Component({
selector: 'app-year-of-birth',
templateUrl: './year-of-birth.component.html',
styleUrls: ['./year-of-birth.component.scss']
})
export class YearOfBirthComponent implements OnInit {
selectedYearOfBirth: number;
birthYearOptions: Array<number> = [];
showYearOfBirthPopup = false;
@Input() dialogProps;
constructor(
private profileService: ProfileService,
private configService: ConfigService,
public resourceService: ResourceService,
private matDialog: MatDialog
) { }
ngOnInit() {
this.initiateYearSelector();
}
submitYearOfBirth() {
if (this.selectedYearOfBirth) {
const req = { dob: this.selectedYearOfBirth.toString() };
this.profileService.updateProfile(req).subscribe();
const dialogRef = this.dialogProps && this.dialogProps.id && this.matDialog.getDialogById(this.dialogProps.id);
dialogRef && dialogRef.close();
}
}
initiateYearSelector() {
const endYear = new Date().getFullYear();
const startYear = endYear - this.configService.constants.SIGN_UP.MAX_YEARS;
for (let year = endYear; year > startYear; year--) {
this.birthYearOptions.push(year);
}
}
changeBirthYear(year) {
this.selectedYearOfBirth = _.get(year, 'value');
}
}
<div class="sb-modal">
<div class="transition ui dimmer page modals active visible">
<div class="ui modal transition active visible small">
<button aria-label="close dialog" mat-dialog-close class="mat-close-btn">
<span>×</span>
</button>
<div class="sb-modal-header">
{{resourceService?.frmelmnts?.lbl?.yearOfBirthHeader}}
</div>
<div class="sb-modal-content o-y-visible">
<div class="ui center aligned segment">
<mat-form-field appearance="fill" class="sb-mat__dropdown mb-16">
<mat-label>{{resourceService?.frmelmnts?.lbl?.yearOfBirth}} <span
class="sb-color-red">*</span>
</mat-label>
<mat-select role="listbox" aria-label="resourceService?.frmelmnts?.lbl?.yearOfBirth" tabindex="0"
class="selection" (selectionChange)="changeBirthYear($event)">
<mat-option class="mat-dropdown__options" role="option" *ngFor="let option of birthYearOptions" [value]="option"
attr.aria-label="{{option}}">{{option}}</mat-option>
</mat-select>
</mat-form-field>
</div>
</div>
<div class="sb-modal-actions">
<button type="button" (click)="submitYearOfBirth()" tabindex="0" [disabled]="!selectedYearOfBirth"
class="sb-btn sb-btn-normal sb-btn-primary">
{{resourceService?.frmelmnts?.lbl?.submit}}
</button>
</div>
</div>
</div>
</div>
Legend
Html element with directive