SHARE
TWEET

Untitled

a guest Jan 17th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit } from '@angular/core';
  2. import { FormGroup, FormControl } from '@angular/forms';
  3. import {Student} from '../student';
  4. import {Place} from '../place';
  5. import {Observable,of} from 'rxjs';
  6. import {StudentServiceService} from '../student-service.service';
  7. import {PlaceService} from '../place.service';
  8. import {map, startWith} from 'rxjs/operators';
  9.  
  10. @Component({
  11.   selector: 'app-new-student',
  12.   templateUrl: './new-student.component.html',
  13.   styleUrls: ['./new-student.component.css']
  14. })
  15.  
  16. export class NewStudentComponent implements OnInit {
  17.   students:Student[];
  18.   places:Place[];
  19.   filteredOptions: Observable<Place[]>;
  20.  
  21.   profileForm=new FormGroup({
  22.     lastName:new FormControl(''),
  23.     firstName:new FormControl(''),
  24.     email:new FormControl(''),
  25.     age:new FormControl(''),
  26.     postCode:new FormControl(''),
  27.   });
  28.   place=new FormControl('');
  29.  
  30.   constructor(
  31.     private studentService:StudentServiceService,
  32.     private placeService:PlaceService,
  33.   ) {
  34.    
  35.   }
  36.  
  37.   ngOnInit(
  38.   ) {
  39.     this.getStudents();
  40.     this.getPlaces();
  41.     this.filteredOptions = this.place.valueChanges
  42.     .pipe(
  43.       startWith(''),
  44.       map(value => this._filter(value))
  45.     );
  46.   }
  47.  
  48.   getPlaces(): void {
  49.     this.placeService.getPlaces()
  50.     .subscribe(places=>this.places=places);
  51.   }
  52.  
  53.  
  54.   getStudents() :void {
  55.     this.studentService.getStudents()
  56.       .subscribe(students=>this.students=students);
  57.   }
  58.  
  59.   onSubmit() {
  60.     console.warn(this.profileForm.value);
  61.   }
  62.   private _filter(value: string): Place[] {
  63.     const filterValue = value.toLowerCase();
  64.     return this.places.filter(places => places.name.toLowerCase().includes(filterValue));
  65.   }
  66. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top