Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import { FormGroup, FormControl } from '@angular/forms';
- import {Student} from '../student';
- import {Place} from '../place';
- import {Observable,of} from 'rxjs';
- import {StudentServiceService} from '../student-service.service';
- import {PlaceService} from '../place.service';
- import {map, startWith} from 'rxjs/operators';
- @Component({
- selector: 'app-new-student',
- templateUrl: './new-student.component.html',
- styleUrls: ['./new-student.component.css']
- })
- export class NewStudentComponent implements OnInit {
- students:Student[];
- places:Place[];
- filteredOptions: Observable<Place[]>;
- profileForm=new FormGroup({
- lastName:new FormControl(''),
- firstName:new FormControl(''),
- email:new FormControl(''),
- age:new FormControl(''),
- postCode:new FormControl(''),
- });
- place=new FormControl('');
- constructor(
- private studentService:StudentServiceService,
- private placeService:PlaceService,
- ) {
- }
- ngOnInit(
- ) {
- this.getStudents();
- this.getPlaces();
- this.filteredOptions = this.place.valueChanges
- .pipe(
- startWith(''),
- map(value => this._filter(value))
- );
- }
- getPlaces(): void {
- this.placeService.getPlaces()
- .subscribe(places=>this.places=places);
- }
- getStudents() :void {
- this.studentService.getStudents()
- .subscribe(students=>this.students=students);
- }
- onSubmit() {
- console.warn(this.profileForm.value);
- }
- private _filter(value: string): Place[] {
- const filterValue = value.toLowerCase();
- return this.places.filter(places => places.name.toLowerCase().includes(filterValue));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement