{"id":20314363,"url":"https://github.com/normandy72/components","last_synced_at":"2026-05-07T13:35:19.750Z","repository":{"id":153902739,"uuid":"589975420","full_name":"Normandy72/Components","owner":"Normandy72","description":"Components \u0026 Component-Based Architecture in AngularJS. Coursera course \"Single Page Web Applications with AngularJS\" by Yaakov Chaikin.","archived":false,"fork":false,"pushed_at":"2023-01-17T16:06:22.000Z","size":101,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-30T14:26:21.291Z","etag":null,"topics":["angular","angularjs","css","css3","html","html5","javascript","js"],"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/Normandy72.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-17T11:34:07.000Z","updated_at":"2023-01-17T15:19:05.000Z","dependencies_parsed_at":"2023-05-06T16:47:31.617Z","dependency_job_id":null,"html_url":"https://github.com/Normandy72/Components","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Normandy72/Components","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Normandy72%2FComponents","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Normandy72%2FComponents/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Normandy72%2FComponents/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Normandy72%2FComponents/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Normandy72","download_url":"https://codeload.github.com/Normandy72/Components/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Normandy72%2FComponents/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32740294,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-07T02:14:30.463Z","status":"ssl_error","status_checked_at":"2026-05-07T02:14:29.405Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["angular","angularjs","css","css3","html","html5","javascript","js"],"created_at":"2024-11-14T18:14:57.823Z","updated_at":"2026-05-07T13:35:19.733Z","avatar_url":"https://github.com/Normandy72.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Components\n#### Components only control their _own_ View and Data\n* Never modify data or DOM outside their own scope.\n* Modifying creates side-effects that lead to chaos.\n* Therefore, Angular components _always_ use isolate scope.\n#### Components have well-defined public API - Inputs and Outputs\n* Inputs: use `\u003c` and `@` bindings only.\n* Never change property of passed in object or array.\n* Outputs: use `\u0026` for component event callbacks.\n* Pass data to callback through param map {key : value}.\n#### Components have well-defined lifecycle\n* `$onInit` - controller initialization code.\n* `$onChanges(changeObj)` - called whenever one-way bindings are updated.\n    * changeObj.currentValue\n    * changeObj.previousValue\n* `$postLink` - similar to 'link' in directive.\n* `$onDestroy` - when scope is about to be destroyed.\n#### Application is a tree of components\n* Entire application should be comprised of components.\n* Each one would have a well-defined input and output.\n* 2-way data binding is minimized as much as possible.\n\n## Steps to create Components\n#### Step 1: Register Component With Module\n```\nangular.module('App', [])\n.component('myComponent', {\n    templateUrl: 'template.html',\n    controller: CompController,\n    bindings: {\n        prop1: '\u003c',\n        prop2: '@',\n        onAction: '\u0026'\n    }\n});\n```\n`'myComponent'` - normalized form. In HTML use `my-component`.\n\n`.component('myComponent', {...});` - simple config object, NOT a function.\n#### Step 2: Configure Component\n```\nangular.module('App', [])\n.component('myComponent', {\n    templateUrl: 'template.html',\n    controller: CompController,\n    bindings: {\n        prop1: '\u003c',\n        prop2: '@',\n        onAction: '\u0026'\n    }\n});\n```\n`templateUrl: 'template.html'` - almost always have a template.\n\n`controller: CompController` - not required. Empty function provided automatically. Placed on scope with label `$ctrl`.\n\n`bindings: {...}` - 'bindings' object is the isolate scope param mapping definition.\n\n#### Step 3: Reference Props in Template\n```\n\u003cdiv\n    ng-click=\"$ctrl.onAction({myArg: 'val'})\"\u003e\n    {{ $ctrl.prop1.prop }} and {{ $ctrl.prop2 }}\n\u003c/div\u003e\n```\n#### Step 4: Use Component in HTML\n```\n\u003cmy-component\n    prop1=\"val-1\"\n    prop2=\"@parentProp\"\n    on-action=\"parentFunction(myArg)\"\u003e\n\n    {{ $ctrl.prop1.prop }} and {{ $ctrl.prop2 }}\n\u003c/my-component\u003e\n```\n***\n#### _Summary_\n* Components encourage component-based architecture, but they don't enforce it 100%, so we must follow conventions.\n* Components should never modify data or DOM that doesn't belong to them. That's why it always has isolate scope and well-defined API.\n* Register component with `.component('name', configObj)`.\n* Provide controller only if you are adding extra functionality. Otherwise, Angular already provides an empty function for us.\n***","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnormandy72%2Fcomponents","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnormandy72%2Fcomponents","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnormandy72%2Fcomponents/lists"}