{"id":21372301,"url":"https://github.com/rxlabz/angular2-typescript-basics","last_synced_at":"2025-08-03T22:36:52.250Z","repository":{"id":32122336,"uuid":"35694848","full_name":"rxlabz/angular2-typescript-basics","owner":"rxlabz","description":"Basic Angular2 (Beta12) / Material2 (alpha.0) / Typescript(1.8) / Firebase demo app","archived":false,"fork":false,"pushed_at":"2016-03-25T09:37:11.000Z","size":238,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-19T23:15:12.491Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rxlabz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-15T20:23:15.000Z","updated_at":"2025-02-20T00:44:32.000Z","dependencies_parsed_at":"2022-09-11T13:12:14.483Z","dependency_job_id":null,"html_url":"https://github.com/rxlabz/angular2-typescript-basics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rxlabz/angular2-typescript-basics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxlabz%2Fangular2-typescript-basics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxlabz%2Fangular2-typescript-basics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxlabz%2Fangular2-typescript-basics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxlabz%2Fangular2-typescript-basics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rxlabz","download_url":"https://codeload.github.com/rxlabz/angular2-typescript-basics/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rxlabz%2Fangular2-typescript-basics/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268623995,"owners_count":24280145,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T08:18:54.298Z","updated_at":"2025-08-03T22:36:52.222Z","avatar_url":"https://github.com/rxlabz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# angular2-typescript-basics\nAngular2(beta9) / Typescript(1.8) with Firebase :\n- Components with properties, events, directives, providers, templateURL and child components\n- DI with providers\n- custom (event) with EventEmitter\n- stores data with Firebase\n- uses NgFor \u0026 NgIf directives\n- FormBuilder\n- Tooltip Attribute directive\n- material2 design alpha.0 integration ( md-button, md-toolbar)\n\n![screen](https://www.evernote.com/l/AAEJ_AvZwDBEBKOuSvmY6whwU28e5OnyxF4B/image.png)\n\n## Setup\ncheck [setup details](https://angular.io/docs/js/latest/quickstart.html)\n\n```bash\nnpm install\n```\n\n## Run\n\ncf. package.json \"scripts\"\n```bash\nnpm run go\n```\n\n## Angular 2\n### Basic Component\n```typescrip\nimport {Component} from \"angular2/core\"\n\n@Component({\n  selector:'nice-component'\n  templateUrl:\"relativePath/to/NiceComponent.html\"\n})\nclass NiceComponent{\n\tproperty:type;\n\tconstructor(){...}\n\taMethod(){...}\n}\n```\n\n### Dependency Injection\n```typescript\n@Component({\n  selector:'nice-component',\n  providers:[AClassToInject]\n})\n\n// ...\n\nclass NiceComponent{\n  ...\n  constructor(injectedInstance:AClassToInject){\n    ...\n  }\n  ...\n}\n\n// ...\n\n@Injectable\nexport class AClassToInject{\n// ...\n}\n\nbootstrap( App, [AClassToInject] );\n```\n\n### EventEmitter\n```typescript\nimport { Component, EventEmitter } from \"angular2/core\";\n\n@Component({\n\t/* ... */\n\tevents:['deleteItem']\n})\n...\nexport class itemRenderer{\n\t...\n\tdeleteItem:EventEmitter;\n\t\n\tconstructor(){\n\t\tthis.deleteItem = new EventEmitter();\n\t}\n\t\n\tremoveItem( item:string ){\n\t\tthis.deleteItem.emit(item);\n\t}\n}\n```\nListen to an event with the new (event) syntax\n\n```html\n\u003citem-renderer (deleteItem)=\"removeItem(item)\" /\u003e\n```\n\n### Component properties\n```typescript\n// itemRenderer.ts\nimport { Component, EventEmitter } from \"angular2/core\";\n\n@Component({\n\t...,\n\tproperties:['item: item']\n})\n```\n\n```html\n// Main.html \n\u003cul\u003e\n\t\u003cli *ngFor=\"#item of model.items\"\u003e\n\t\t\u003citem-renderer [item]=\"item\" /\u003e \u003c!-- new [property] syntax --\u003e\n\t\u003c/li\u003e\n\u003c/ul\u003e\n```\n### Component sub-components\nIf a component A uses a component B, B must be declared in A @View.directives\n\n```typescript\n@Component({\n\t...,\n\tdirectives:[ ItemForm, ItemRenderer]\n})\n\n```\n\n### Firebase / AngularFire storage \nFirebase library from https://github.com/Microsoft/ngconf2015demo / https://github.com/davideast/ng2do\n```typescript\n// ItemStore.ts\nvar data = new AngularFire(new Firebase('https://webapi.firebaseio-demo.com/test'));\nthis.store = data.asArray();\n\n// add, remove... an item\nthis.store.add( ... );\nthis.store.remove( ... );\n\n```\n\n### For directive \n```html\n\u003cul\u003e\n\t\u003cli *ngFor=\"#item of items\" \u003e{{ item.title }}\u003c/li\u003e\n\u003c/ul\u003e\n```\n\n### If directive \n```html\n\u003cdiv *ngIf=\"aComponentProperty\"\u003e...\u003c/div\u003e\n```\n\n### Forms\n\n```html\n\u003cform (ngSubmit)=\"save($event)\" [ngFormModel]=\"todoForm\"\u003e\n\t\u003cdiv [hidden]=\"!hasError\"\u003eRequired\u003c/div\u003e\n\t\u003cinput ngControl=\"title\" #tInput type=\"text\"\n\t\t   [value]=\"item.title\"\n\t\t   (keyup)=\"onKey($event)\"\n\t/\u003e\n\t\u003cbutton type=\"submit\"\u003eSave\u003c/button\u003e\n\n\u003c/form\u003e\n```\n\n```javascript\n\nprivate todoForm:ControlGroup;\n\nvar fb = new FormBuilder()\nthis.todoForm = fb.group({\n\ttitle: [ this._item.title, Validators.required ]\n});\n\nif( this.todoForm.valid ){\n\tthis.hasError = false;\n\tthis.item.title = this.todoForm.value.title;\n} else // ...\n```\n\n### Attribute Directive\n\n**Host template** [itemRenderer.html](https://github.com/rxlabz/angular2-typescript-basics/blob/master/app/components/itemRenderer.html)\n\n```html\n\u003cdiv class=\"content\" *ngIf=\"!editable\"\n\t [toolTiper]=\"item.creationDate\"\u003e\n\u003c!-- ... --\u003e\n\u003c/div\u003e\n```\n**Attribute directive** [tooltiper.directive.ts](https://github.com/rxlabz/angular2-typescript-basics/blob/master/app/directives/tooltiper.directive.ts)\n```typescript\n@Directive({\n        selector: '[toolTiper]',\n        host: {\n            '(mouseenter)': 'onMouseEnter()',\n            '(mouseleave)': 'onMouseLeave()'\n        }\n    }\n)\nexport class ToolTiper {\n\n@Input('toolTiper') toolTipContent:string = '';\n\ntooltipElement:ComponentRef;\n\nconstructor(\n\tprivate el:ElementRef,\n\tprivate container:ViewContainerRef,\n\tprivate renderer:Renderer,\n\tprivate loader:DynamicComponentLoader\n\t) {\n        loader.loadNextToLocation(Tooltip, this.el)\n            .then(ref =\u003e this.tooltipElement = ref);\n    }\n}\n```\n\n\n### \u003ca href=\"\" target=\"_blank\"\u003eMaterial Design 2 alpha\u003c/a\u003e\n\n+ \u003ca href=\"https://github.com/angular/material2/tree/master/src/demo-app\" target=\"_blank\"\u003edemo app\u003c/a\u003e\n\n+ \u003ca href=\"https://design.google.com/icons/\" target=\"_blank\"\u003eMaterial Design icons\u003c/a\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frxlabz%2Fangular2-typescript-basics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frxlabz%2Fangular2-typescript-basics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frxlabz%2Fangular2-typescript-basics/lists"}