├── README.md ├── angular.json ├── package.json ├── src ├── app │ ├── app.component.css │ ├── app.component.html │ ├── app.component.ts │ ├── app.module.ts │ ├── employee-component │ │ ├── employee-component.component.css │ │ ├── employee-component.component.html │ │ ├── employee-component.component.ts │ │ └── employee.ts │ └── shared │ │ └── star │ │ ├── star.component.css │ │ ├── star.component.html │ │ └── star.component.ts ├── index.html ├── main.ts ├── polyfills.ts └── styles.css └── tsconfig.json /README.md: -------------------------------------------------------------------------------- 1 | # angular-@output 2 | 3 | ![image](https://user-images.githubusercontent.com/38757471/130340987-ba2a491b-a0c7-43fc-ac04-89048e41419d.png) 4 | 5 | 6 | employee.ts (parent) 7 | 8 | ```js 9 | export interface IEmployee { 10 | id: number; 11 | code: string; 12 | name: string; 13 | salary: number; 14 | starRating: number; 15 | } 16 | ``` 17 | 18 | employee-component.component.ts (parent) 19 | 20 | ```js 21 | import { Component, OnInit } from '@angular/core'; 22 | import { IEmployee } from './employee'; 23 | 24 | @Component({ 25 | selector: 'app-employee-component', 26 | templateUrl: './employee-component.component.html', 27 | styleUrls: ['./employee-component.component.css'] 28 | }) 29 | export class EmployeeComponentComponent implements OnInit { 30 | constructor() {} 31 | 32 | ngOnInit() { 33 | this.listFilter = 'Patel'; 34 | } 35 | 36 | pageTitle: string = 'Employee List'; 37 | 38 | private _listFilter: string = ''; 39 | 40 | get listFilter(): string { 41 | return this._listFilter; 42 | } 43 | 44 | set listFilter(value: string) { 45 | this._listFilter = value; 46 | console.log('In Setter:', value); 47 | this.filteredEmployees = this.performFilter(value); 48 | } 49 | 50 | filteredEmployees: IEmployee[] = []; 51 | employees: IEmployee[] = [ 52 | { 53 | id: 1, 54 | code: 'VOD1410', 55 | name: 'Akshay Patel', 56 | salary: 3000, 57 | starRating: 3.5 58 | }, 59 | { 60 | id: 2, 61 | code: 'VOD1710', 62 | name: 'Panth Patel', 63 | salary: 1500, 64 | starRating: 4 65 | }, 66 | { 67 | id: 2, 68 | code: 'VOD0408', 69 | name: 'Satish Patel', 70 | salary: 5000, 71 | starRating: 4.5 72 | } 73 | ]; 74 | 75 | performFilter(filterBy: string): IEmployee[] { 76 | filterBy = filterBy.toLocaleLowerCase(); 77 | return this.employees.filter((employee: IEmployee) => 78 | employee.name.toLocaleLowerCase().includes(filterBy) 79 | ); 80 | } 81 | 82 | onRatingClicked(message: string): void { 83 | this.pageTitle = 'Employee List ' + message; 84 | } 85 | } 86 | 87 | ``` 88 | employee-component.component.html (parent) 89 | 90 | ```html 91 |
92 |
93 | {{pageTitle}} 94 |
95 |
96 | 97 |
98 |
99 |
100 | Filter By: {{listFilter}} 101 |
102 |
103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 122 | 123 |
IdCodeNameSalaryRating
{{employee.id}}{{employee.code}}{{employee.name}}{{employee.salary}} 117 | 121 |
124 |
125 |
126 | ``` 127 | star.component.ts (child) 128 | 129 | ```js 130 | import { 131 | Component, 132 | EventEmitter, 133 | Input, 134 | OnChanges, 135 | OnInit, 136 | Output 137 | } from '@angular/core'; 138 | 139 | @Component({ 140 | selector: 'app-star', 141 | templateUrl: './star.component.html', 142 | styleUrls: ['./star.component.css'] 143 | }) 144 | export class StarComponent implements OnChanges { 145 | constructor() {} 146 | 147 | @Input() rating: number = 0; 148 | cropWidth: number = 75; 149 | 150 | ngOnChanges(): void { 151 | this.cropWidth = this.rating * (75 / 5); 152 | } 153 | 154 | @Output() ratingClicked: EventEmitter = new EventEmitter(); 155 | 156 | onClick() { 157 | this.ratingClicked.emit(`The rating ${this.rating} was clicked!`); 158 | } 159 | } 160 | ``` 161 | 162 | star.component.html (child) 163 | 164 | ```html 165 |
166 |
167 | 168 | 169 | 170 | 171 | 172 |
173 |
174 | ``` 175 | 176 | star.component.css (child) 177 | 178 | ```css 179 | .crop { 180 | overflow: hidden; 181 | } 182 | div { 183 | cursor: pointer; 184 | } 185 | ``` 186 | 187 | style.css 188 | 189 | Install bootstrap font-awesome and import in style.css 190 | 191 | ```css 192 | @import '~bootstrap/dist/css/bootstrap.min.css'; 193 | @import 'font-awesome/css/font-awesome.min.css'; 194 | ``` 195 | 196 | app.module.ts 197 | 198 | ```js 199 | import { NgModule } from '@angular/core'; 200 | import { BrowserModule } from '@angular/platform-browser'; 201 | import { FormsModule } from '@angular/forms'; 202 | 203 | import { AppComponent } from './app.component'; 204 | import { EmployeeComponentComponent } from './employee-component/employee-component.component'; 205 | import { StarComponent } from './shared/star/star.component'; 206 | 207 | @NgModule({ 208 | imports: [BrowserModule, FormsModule], 209 | declarations: [AppComponent, EmployeeComponentComponent, StarComponent], 210 | bootstrap: [AppComponent] 211 | }) 212 | export class AppModule {} 213 | ``` 214 | 215 | app.component.html 216 | 217 | ```html 218 | 219 | ``` 220 | ![image](https://user-images.githubusercontent.com/38757471/130340757-7250c30a-6a2d-4c92-b66f-98628f01870f.png) 221 | 222 | 223 | 224 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "demo": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "prefix": "app", 11 | "schematics": {}, 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/demo", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "src/tsconfig.app.json", 21 | "assets": [ 22 | "src/favicon.ico", 23 | "src/assets" 24 | ], 25 | "styles": [ 26 | "src/styles.css" 27 | ], 28 | "scripts": [] 29 | }, 30 | "configurations": { 31 | "production": { 32 | "fileReplacements": [ 33 | { 34 | "replace": "src/environments/environment.ts", 35 | "with": "src/environments/environment.prod.ts" 36 | } 37 | ], 38 | "optimization": true, 39 | "outputHashing": "all", 40 | "sourceMap": false, 41 | "extractCss": true, 42 | "namedChunks": false, 43 | "aot": true, 44 | "extractLicenses": true, 45 | "vendorChunk": false, 46 | "buildOptimizer": true 47 | } 48 | } 49 | }, 50 | "serve": { 51 | "builder": "@angular-devkit/build-angular:dev-server", 52 | "options": { 53 | "browserTarget": "demo:build" 54 | }, 55 | "configurations": { 56 | "production": { 57 | "browserTarget": "demo:build:production" 58 | } 59 | } 60 | }, 61 | "extract-i18n": { 62 | "builder": "@angular-devkit/build-angular:extract-i18n", 63 | "options": { 64 | "browserTarget": "demo:build" 65 | } 66 | }, 67 | "test": { 68 | "builder": "@angular-devkit/build-angular:karma", 69 | "options": { 70 | "main": "src/test.ts", 71 | "polyfills": "src/polyfills.ts", 72 | "tsConfig": "src/tsconfig.spec.json", 73 | "karmaConfig": "src/karma.conf.js", 74 | "styles": [ 75 | "styles.css" 76 | ], 77 | "scripts": [], 78 | "assets": [ 79 | "src/favicon.ico", 80 | "src/assets" 81 | ] 82 | } 83 | }, 84 | "lint": { 85 | "builder": "@angular-devkit/build-angular:tslint", 86 | "options": { 87 | "tsConfig": [ 88 | "src/tsconfig.app.json", 89 | "src/tsconfig.spec.json" 90 | ], 91 | "exclude": [ 92 | "**/node_modules/**" 93 | ] 94 | } 95 | } 96 | } 97 | } 98 | }, 99 | "defaultProject": "demo" 100 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular", 3 | "version": "0.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "@angular/animations": "^12.1.0", 7 | "@angular/common": "^12.1.0", 8 | "@angular/compiler": "^12.1.0", 9 | "@angular/core": "^12.1.0", 10 | "@angular/forms": "^12.1.0", 11 | "@angular/platform-browser": "^12.1.0", 12 | "@angular/platform-browser-dynamic": "^12.1.0", 13 | "@angular/router": "^12.1.0", 14 | "@popperjs/core": "^2.9.3", 15 | "bootstrap": "^5.1.0", 16 | "font-awesome": "^4.7.0", 17 | "rxjs": "^7.1.0", 18 | "tslib": "^2.3.0", 19 | "zone.js": "^0.11.4" 20 | }, 21 | "scripts": { 22 | "ng": "ng", 23 | "start": "ng serve", 24 | "build": "ng build", 25 | "test": "ng test", 26 | "lint": "ng lint", 27 | "e2e": "ng e2e" 28 | }, 29 | "devDependencies": { 30 | "@angular-devkit/build-angular": "~0.1100.4", 31 | "@angular/cli": "~11.0.4", 32 | "@angular/compiler-cli": "~11.0.4", 33 | "@types/jasmine": "~3.6.0", 34 | "@types/node": "^12.11.1", 35 | "codelyzer": "^6.0.0", 36 | "jasmine-core": "~3.6.0", 37 | "jasmine-spec-reporter": "~5.0.0", 38 | "karma": "~5.1.0", 39 | "karma-chrome-launcher": "~3.1.0", 40 | "karma-coverage": "~2.0.3", 41 | "karma-jasmine": "~4.0.0", 42 | "karma-jasmine-html-reporter": "^1.5.0", 43 | "protractor": "~7.0.0", 44 | "ts-node": "~8.3.0", 45 | "tslint": "~6.1.0", 46 | "typescript": "~4.0.2" 47 | } 48 | } -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- 1 | p { 2 | font-family: Lato; 3 | } -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'my-app', 5 | templateUrl: './app.component.html', 6 | styleUrls: [ './app.component.css' ] 7 | }) 8 | export class AppComponent { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { BrowserModule } from '@angular/platform-browser'; 3 | import { FormsModule } from '@angular/forms'; 4 | 5 | import { AppComponent } from './app.component'; 6 | import { EmployeeComponentComponent } from './employee-component/employee-component.component'; 7 | import { StarComponent } from './shared/star/star.component'; 8 | 9 | @NgModule({ 10 | imports: [BrowserModule, FormsModule], 11 | declarations: [AppComponent, EmployeeComponentComponent, StarComponent], 12 | bootstrap: [AppComponent] 13 | }) 14 | export class AppModule {} 15 | -------------------------------------------------------------------------------- /src/app/employee-component/employee-component.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akshayblevel/angular--output/cbf831b5d9b9e249fefe3a4a5b0dfd37d11accda/src/app/employee-component/employee-component.component.css -------------------------------------------------------------------------------- /src/app/employee-component/employee-component.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{pageTitle}} 4 |
5 |
6 | 7 |
8 |
9 |
10 | Filter By: {{listFilter}} 11 |
12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 32 | 33 |
IdCodeNameSalaryRating
{{employee.id}}{{employee.code}}{{employee.name}}{{employee.salary}} 27 | 31 |
34 |
35 |
36 | -------------------------------------------------------------------------------- /src/app/employee-component/employee-component.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { IEmployee } from './employee'; 3 | 4 | @Component({ 5 | selector: 'app-employee-component', 6 | templateUrl: './employee-component.component.html', 7 | styleUrls: ['./employee-component.component.css'] 8 | }) 9 | export class EmployeeComponentComponent implements OnInit { 10 | constructor() {} 11 | 12 | ngOnInit() { 13 | this.listFilter = 'Patel'; 14 | } 15 | 16 | pageTitle: string = 'Employee List'; 17 | 18 | private _listFilter: string = ''; 19 | 20 | get listFilter(): string { 21 | return this._listFilter; 22 | } 23 | 24 | set listFilter(value: string) { 25 | this._listFilter = value; 26 | console.log('In Setter:', value); 27 | this.filteredEmployees = this.performFilter(value); 28 | } 29 | 30 | filteredEmployees: IEmployee[] = []; 31 | employees: IEmployee[] = [ 32 | { 33 | id: 1, 34 | code: 'VOD1410', 35 | name: 'Akshay Patel', 36 | salary: 3000, 37 | starRating: 3.5 38 | }, 39 | { 40 | id: 2, 41 | code: 'VOD1710', 42 | name: 'Panth Patel', 43 | salary: 1500, 44 | starRating: 4 45 | }, 46 | { 47 | id: 2, 48 | code: 'VOD0408', 49 | name: 'Satish Patel', 50 | salary: 5000, 51 | starRating: 4.5 52 | } 53 | ]; 54 | 55 | performFilter(filterBy: string): IEmployee[] { 56 | filterBy = filterBy.toLocaleLowerCase(); 57 | return this.employees.filter((employee: IEmployee) => 58 | employee.name.toLocaleLowerCase().includes(filterBy) 59 | ); 60 | } 61 | 62 | onRatingClicked(message: string): void { 63 | this.pageTitle = 'Employee List ' + message; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/app/employee-component/employee.ts: -------------------------------------------------------------------------------- 1 | export interface IEmployee { 2 | id: number; 3 | code: string; 4 | name: string; 5 | salary: number; 6 | starRating: number; 7 | } 8 | -------------------------------------------------------------------------------- /src/app/shared/star/star.component.css: -------------------------------------------------------------------------------- 1 | .crop { 2 | overflow: hidden; 3 | } 4 | div { 5 | cursor: pointer; 6 | } 7 | -------------------------------------------------------------------------------- /src/app/shared/star/star.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | 5 | 6 | 7 | 8 |
9 |
10 | -------------------------------------------------------------------------------- /src/app/shared/star/star.component.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Component, 3 | EventEmitter, 4 | Input, 5 | OnChanges, 6 | OnInit, 7 | Output 8 | } from '@angular/core'; 9 | 10 | @Component({ 11 | selector: 'app-star', 12 | templateUrl: './star.component.html', 13 | styleUrls: ['./star.component.css'] 14 | }) 15 | export class StarComponent implements OnChanges { 16 | constructor() {} 17 | 18 | @Input() rating: number = 0; 19 | cropWidth: number = 75; 20 | 21 | ngOnChanges(): void { 22 | this.cropWidth = this.rating * (75 / 5); 23 | } 24 | 25 | @Output() ratingClicked: EventEmitter = new EventEmitter(); 26 | 27 | onClick() { 28 | this.ratingClicked.emit(`The rating ${this.rating} was clicked!`); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | loading -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import './polyfills'; 2 | 3 | import { enableProdMode } from '@angular/core'; 4 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 5 | 6 | import { AppModule } from './app/app.module'; 7 | 8 | platformBrowserDynamic().bootstrapModule(AppModule).then(ref => { 9 | // Ensure Angular destroys itself on hot reloads. 10 | if (window['ngRef']) { 11 | window['ngRef'].destroy(); 12 | } 13 | window['ngRef'] = ref; 14 | 15 | // Otherwise, log the boot error 16 | }).catch(err => console.error(err)); -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/set'; 35 | 36 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 37 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 38 | 39 | /** IE10 and IE11 requires the following to support `@angular/animation`. */ 40 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 41 | 42 | 43 | /** Evergreen browsers require these. **/ 44 | // import 'core-js/es6/reflect'; 45 | // import 'core-js/es7/reflect'; 46 | 47 | 48 | /** 49 | * Web Animations `@angular/platform-browser/animations` 50 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 51 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 52 | */ 53 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 54 | 55 | 56 | 57 | /*************************************************************************************************** 58 | * Zone JS is required by Angular itself. 59 | */ 60 | import 'zone.js/dist/zone'; // Included with Angular CLI. 61 | 62 | 63 | /*************************************************************************************************** 64 | * APPLICATION IMPORTS 65 | */ 66 | 67 | /** 68 | * Date, currency, decimal and percent pipes. 69 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10 70 | */ 71 | // import 'intl'; // Run `npm install --save intl`. -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | @import '~bootstrap/dist/css/bootstrap.min.css'; 2 | @import '~font-awesome/css/font-awesome.min.css'; 3 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | }, 22 | "angularCompilerOptions": { 23 | "enableIvy": true, 24 | "fullTemplateTypeCheck": true, 25 | "strictInjectionParameters": true 26 | } 27 | } --------------------------------------------------------------------------------