Skip to content

Commit

Permalink
Updated demo app to use NgxMatTypeahead directive for typeahead funct…
Browse files Browse the repository at this point in the history
…ionality
  • Loading branch information
mrsan22 committed May 24, 2018
1 parent 29b1840 commit 7836840
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 45 deletions.
6 changes: 6 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"src/assets"
],
"styles": [
{
"input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
},
"src/styles.css"
],
"scripts": []
Expand Down Expand Up @@ -72,6 +75,9 @@
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": [
{
"input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
},
"src/styles.css"
],
"scripts": [],
Expand Down
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,26 @@
},
"private": true,
"dependencies": {
"@angular/animations": "^6.0.2",
"@angular/common": "^6.0.2",
"@angular/core": "^6.0.2",
"@angular/compiler": "^6.0.2",
"@angular/animations": "^6.0.2",
"@angular/core": "^6.0.2",
"@angular/forms": "^6.0.2",
"@angular/http": "^6.0.2",
"@angular/material": "^6.1.0",
"@angular/platform-browser": "^6.0.2",
"@angular/platform-browser-dynamic": "^6.0.2",
"@angular/router": "^6.0.2",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
"zone.js": "^0.8.26",
"@angular/cdk": "^6.1.0"
},
"devDependencies": {
"@angular/compiler-cli": "^6.0.2",
"@angular-devkit/build-ng-packagr": "~0.6.3",
"@angular-devkit/build-angular": "~0.6.3",
"ng-packagr": "^3.0.0-rc.2",
"tsickle": ">=0.25.5",
"tslib": "^1.7.1",
"typescript": "~2.7.2",
"@angular-devkit/build-ng-packagr": "~0.6.3",
"@angular/cli": "~6.0.3",
"@angular/compiler-cli": "^6.0.2",
"@angular/language-service": "^6.0.2",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
Expand All @@ -45,8 +43,12 @@
"karma-coverage-istanbul-reporter": "~1.4.2",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"ng-packagr": "^3.0.0-rc.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1"
"tsickle": ">=0.25.5",
"tslib": "^1.7.1",
"tslint": "~5.9.1",
"typescript": "~2.7.2"
}
}
30 changes: 11 additions & 19 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
<!--The content below is only a placeholder and can be replaced.-->
<div style="text-align:center">
<h1>
Welcome to {{ title }}!
</h1>
<img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
<h3>Typeahead demo app using Angular Material</h3>
<div [formGroup]="testFormGroup">
<mat-form-field>
<input matInput NgxMatTypeahead (filteredDataList)="getFilteredSuggestions($event)" formControlName="country" [matAutocomplete]="countryAuto"
placeholder="Choose Country">
<mat-autocomplete #countryAuto="matAutocomplete">
<mat-option *ngFor="let country of countries" [value]="country">
{{country}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</div>
<h2>Here are some links to help you start: </h2>
<ul>
<li>
<h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
</li>
<li>
<h2><a target="_blank" rel="noopener" href="https://github.com/angular/angular-cli/wiki">CLI Documentation</a></h2>
</li>
<li>
<h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
</li>
</ul>

20 changes: 16 additions & 4 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import { Component } from '@angular/core';

import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { AppService } from './app.service';
@Component({
selector: 'mat-ta-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'mat-ta';
export class AppComponent implements OnInit {
constructor(private appService: AppService) {}

testFormGroup: FormGroup = new FormGroup({ country: new FormControl('') });
countries: Array<string> = [];

ngOnInit() {
this.appService.getCountries().subscribe(data => (this.countries = data));
}

getFilteredSuggestions(filteredDataLst: Array<any>) {
this.countries = [...filteredDataLst];
}
}
23 changes: 16 additions & 7 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core';

import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatAutocompleteModule, MatInputModule } from '@angular/material';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgxMatTypeaheadModule } from 'NgxMatTypeahead';
import { AppComponent } from './app.component';

@NgModule({
declarations: [
AppComponent
],
declarations: [AppComponent],
imports: [
BrowserModule
BrowserModule,
BrowserAnimationsModule,
FormsModule,
ReactiveFormsModule,
MatInputModule,
MatAutocompleteModule,
HttpClientModule,
NgxMatTypeaheadModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
export class AppModule {}
19 changes: 19 additions & 0 deletions src/app/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

@Injectable({
providedIn: 'root'
})
export class AppService {
constructor(private http: HttpClient) {}

getCountries(): Observable<Array<string>> {
return this.http.get<Array<string>>('../assets/countries.json').pipe(
map(data => {
return data['countries'];
})
);
}
}
3 changes: 3 additions & 0 deletions src/assets/countries.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"countries": ["United States", "United Kingdom", "China", "Japan", "India", "Russia", "Canada", "Brazil"]
}
2 changes: 2 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<!doctype html>
<html lang="en">
<head>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
<meta charset="utf-8">
<title>MatTypeaheadLibrary</title>
<base href="/">
Expand Down
4 changes: 4 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/* You can add global styles to this file, and also import other style files */

body {
margin: 20px;
}
18 changes: 13 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
dependencies:
tslib "^1.9.0"

"@angular/cdk@^6.1.0":
version "6.1.0"
resolved "https://registry.yarnpkg.com/@angular/cdk/-/cdk-6.1.0.tgz#14ae46730315d40b5a642daa8f5f80815930085c"
dependencies:
tslib "^1.7.1"

"@angular/cli@~6.0.3":
version "6.0.3"
resolved "https://registry.yarnpkg.com/@angular/cli/-/cli-6.0.3.tgz#a7a2defdaa2a9f2914aadb7e0a25d9a43d8346c4"
Expand Down Expand Up @@ -166,6 +172,12 @@
version "6.0.3"
resolved "https://registry.yarnpkg.com/@angular/language-service/-/language-service-6.0.3.tgz#7182f3824520fd5f5f6173fdee80284356d29d08"

"@angular/material@^6.1.0":
version "6.1.0"
resolved "https://registry.yarnpkg.com/@angular/material/-/material-6.1.0.tgz#c13f4fb38ae6f52c7c49cd8d3ae4baca4abd36ab"
dependencies:
tslib "^1.7.1"

"@angular/platform-browser-dynamic@^6.0.2":
version "6.0.3"
resolved "https://registry.yarnpkg.com/@angular/platform-browser-dynamic/-/platform-browser-dynamic-6.0.3.tgz#b27e26c06df4ce34879cefd818e7ff394764f834"
Expand Down Expand Up @@ -4042,18 +4054,14 @@ minimalistic-crypto-utils@^1.0.0, minimalistic-crypto-utils@^1.0.1:
dependencies:
brace-expansion "^1.1.7"

[email protected]:
[email protected], minimist@~0.0.1:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"

minimist@^1.1.0, minimist@^1.1.3, minimist@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"

minimist@~0.0.1:
version "0.0.10"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"

minipass@^2.2.1, minipass@^2.3.3:
version "2.3.3"
resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.3.3.tgz#a7dcc8b7b833f5d368759cce544dccb55f50f233"
Expand Down

0 comments on commit 7836840

Please sign in to comment.