Created
December 2, 2016 09:40
-
-
Save machariamarigi/17a1c7596fb349eeabd74a640336c1cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ListingType } from './../models/typesListings'; | |
import { ListingTypesService } from './../services/listing-types.service'; | |
import { ListingsService } from './../services/listings.service'; | |
import { Listing } from './../models/listingModel'; | |
import { Component, OnInit } from '@angular/core'; | |
import { FormGroup, FormBuilder, Validators } from '@angular/forms' | |
@Component({ | |
selector: 'app-newlisting', | |
templateUrl: './newlisting.component.html', | |
styleUrls: ['./newlisting.component.css'] | |
}) | |
export class NewlistingComponent implements OnInit { | |
listing: FormGroup; | |
listingTypes: ListingType[]; | |
constructor( | |
public listingservice: ListingsService, | |
public listingTypesService: ListingTypesService, | |
private fb: FormBuilder | |
) { } | |
ngOnInit() { | |
this.listing = this.fb.group({ | |
name: [''], | |
type: ['', Validators.required], | |
owner: [''], | |
price: ['', Validators.required], | |
description: [''], | |
location: ['', Validators.required], | |
image1: [''], | |
image2: [''], | |
image3: [''], | |
}) | |
this.listingTypesService.getTypes() | |
.subscribe(listingTypes => { | |
this.listingTypes = listingTypes; | |
}); | |
} | |
onSubmit({ value, valid }: { value: Listing, valid: boolean }) { | |
console.log(value, valid); | |
this.listingservice.addListing(value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment