Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

project done #7

Open
wants to merge 1 commit into
base: get-started
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
19 changes: 18 additions & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
Fairhouse App is running
<main>
<header>
<img src="../assets/logo.svg" alt="fairhouse">FairHouse
</header>
<section>
<app-housing-list [locationList]="housingLocationList" (selectedLocationEvent)="updateSelectedLocation($event)"></app-housing-list>
</section>
<article>
<ng-container *ngIf="selectedLocation">
<img [src]="selectedLocation?.photo">
<p>{{selectedLocation?.name}}</p>
<p>{{selectedLocation?.city}}, {{selectedLocation?.state}}</p>
<p>Available Units: {{selectedLocation?.availableUnits}}</p>
<p>{{selectedLocation?.laundry ? "Has laundry" : "Does Not have laundry"}}</p>
<p>{{selectedLocation?.wifi ? "Has wifi" : "Does Not have wifi"}}</p>
</ng-container>
</article>
</main>
38 changes: 37 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
import { Component } from '@angular/core';

import { HousingLocation } from './housing-location';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
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;
}
}

4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions src/app/housing-list/housing-list.component.css
Original file line number Diff line number Diff line change
@@ -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;
}
9 changes: 9 additions & 0 deletions src/app/housing-list/housing-list.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<label for="location-search">Search for a new place</label>
<input id="location-search" #search placeholder="Ex: Chicago">
<button (click)="searchHousingLocations(search.value)" >Search</button>
<article *ngFor="let location of results">
<img [src]="location.photo" [alt]="location.name">
<p>{{location.name}}</p>
<p>{{location.city}}, {{location.state}}</p>
<button (click)="selectHousingLocation(location)" >View</button>
</article>
25 changes: 25 additions & 0 deletions src/app/housing-list/housing-list.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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<HousingListComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ HousingListComponent ]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(HousingListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
28 changes: 28 additions & 0 deletions src/app/housing-list/housing-list.component.ts
Original file line number Diff line number Diff line change
@@ -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<HousingLocation>();
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)
}
}
9 changes: 9 additions & 0 deletions src/app/housing-location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface HousingLocation {
name: string,
city: string,
state: string,
photo: string,
availableUnits: number,
wifi: boolean,
laundry: boolean
}