diff --git a/README.md b/README.md index d71cf23..2fc467f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +I just started to learn Angular, this is my first project from Google: + + # Introduction to Angular Codelab \In this codelab, you'll build a housing app with Angular. The completed app will feature the ability to view home listings based on user search, and view details of a housing location. diff --git a/src/app/app.component.html b/src/app/app.component.html index ccd6a1a..8310db6 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1 +1,18 @@ -Fairhouse App is running \ No newline at end of file +
+
+ fairhouseFairHouse +
+
+ +
+
+ + +

{{selectedLocation?.name}}

+

{{selectedLocation?.city}}, {{selectedLocation?.state}}

+

Available Units: {{selectedLocation?.availableUnits}}

+

{{selectedLocation?.laundry ? "Has laundry" : "Does Not have laundry"}}

+

{{selectedLocation?.wifi ? "Has wifi" : "Does Not have wifi"}}

+
+
+
\ No newline at end of file diff --git a/src/app/app.component.ts b/src/app/app.component.ts index c988189..4fc74ef 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,5 +1,5 @@ import { Component } from '@angular/core'; - +import { HousingLocation } from './housing-location'; @Component({ selector: 'app-root', templateUrl: './app.component.html', @@ -7,4 +7,40 @@ import { Component } from '@angular/core'; }) export class AppComponent { title = 'fairhouse'; + housingLocationList: HousingLocation[] = [ + { + name: "Acme Fresh Start Housing", + city: "Chicago", + state: "IL", + photo: "../assets/housing-1.jpg", + availableUnits: 4, + wifi: true, + laundry: true, + }, + { + name: "A113 Transitional Housing", + city: "Santa Monica", + state: "CA", + photo: "../assets/housing-2.jpg", + availableUnits: 0, + wifi: false, + laundry: true, + }, + { + name: "Warm Beds Housing Support", + city: "Juneau", + state: "AK", + photo: "../assets/housing-3.jpg", + availableUnits: 1, + wifi: false, + laundry: false, + } + ]; + + selectedLocation: HousingLocation | undefined; + + updateSelectedLocation (location: HousingLocation) { + this.selectedLocation = location; + } } + diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 8dfc1d6..82233e0 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -2,10 +2,12 @@ import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; +import { HousingListComponent } from './housing-list/housing-list.component'; @NgModule({ declarations: [ - AppComponent + AppComponent, + HousingListComponent ], imports: [ BrowserModule diff --git a/src/app/housing-list/housing-list.component.css b/src/app/housing-list/housing-list.component.css new file mode 100644 index 0000000..35d0358 --- /dev/null +++ b/src/app/housing-list/housing-list.component.css @@ -0,0 +1,46 @@ +input, button { + border: solid 1px #555B6E; + border-radius: 2px; + display: inline-block; + padding: 0; +} +input { + width: 400px; + height: 40px; + border-radius: 2px 0 0 2px; + color: #888c9c; + border: solid 1px #888c9c; + padding: 0 5px 0 10px; +} + +button { + width: 70px; + height: 42px; + background-color: #4468e8; + color: white; + border: solid 1px #4468e8; + border-radius: 0 2px 2px 0; +} + +article { + margin: 40px 0 10px 0; + color: #202845; +} +article, article > p { + color: #202845; +} + +article> p:first-of-type { + font-weight: bold; + font-size: 22pt; +} + +img { + width: 490px; + border-radius: 5pt; +} + +label { + display: block; + color: #888c9c; +} \ No newline at end of file diff --git a/src/app/housing-list/housing-list.component.html b/src/app/housing-list/housing-list.component.html new file mode 100644 index 0000000..9f4215e --- /dev/null +++ b/src/app/housing-list/housing-list.component.html @@ -0,0 +1,9 @@ + + + +
+ +

{{location.name}}

+

{{location.city}}, {{location.state}}

+ +
\ No newline at end of file diff --git a/src/app/housing-list/housing-list.component.spec.ts b/src/app/housing-list/housing-list.component.spec.ts new file mode 100644 index 0000000..ee08bcd --- /dev/null +++ b/src/app/housing-list/housing-list.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { HousingListComponent } from './housing-list.component'; + +describe('HousingListComponent', () => { + let component: HousingListComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ HousingListComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(HousingListComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/housing-list/housing-list.component.ts b/src/app/housing-list/housing-list.component.ts new file mode 100644 index 0000000..dddf326 --- /dev/null +++ b/src/app/housing-list/housing-list.component.ts @@ -0,0 +1,28 @@ +import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; +import { HousingLocation } from '../housing-location'; +@Component({ + selector: 'app-housing-list', + templateUrl: './housing-list.component.html', + styleUrls: ['./housing-list.component.css'] +}) +export class HousingListComponent implements OnInit { + + @Input() locationList: HousingLocation[] = []; + results: HousingLocation[] = []; + @Output() selectedLocationEvent = new EventEmitter(); + constructor() { } + + ngOnInit(): void { + } + + searchHousingLocations(searchText: string) { + if (!searchText) return + this.results = this.locationList + .filter( + location => location.city.toLowerCase().includes(searchText.toLowerCase())) + } + + selectHousingLocation (location: HousingLocation) { + this.selectedLocationEvent.emit(location) + } +} diff --git a/src/app/housing-location.ts b/src/app/housing-location.ts new file mode 100644 index 0000000..f950c94 --- /dev/null +++ b/src/app/housing-location.ts @@ -0,0 +1,9 @@ +export interface HousingLocation { + name: string, + city: string, + state: string, + photo: string, + availableUnits: number, + wifi: boolean, + laundry: boolean +}