{"id":16647261,"url":"https://github.com/andresaraujo/angular2_cheatsheet_dart","last_synced_at":"2025-12-26T02:39:42.870Z","repository":{"id":32460415,"uuid":"36040073","full_name":"andresaraujo/angular2_cheatsheet_dart","owner":"andresaraujo","description":null,"archived":false,"fork":false,"pushed_at":"2015-09-05T15:58:31.000Z","size":156,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-18T22:58:31.243Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"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/andresaraujo.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-21T22:19:00.000Z","updated_at":"2022-10-04T15:59:23.000Z","dependencies_parsed_at":"2022-08-24T12:50:13.071Z","dependency_job_id":null,"html_url":"https://github.com/andresaraujo/angular2_cheatsheet_dart","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andresaraujo%2Fangular2_cheatsheet_dart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andresaraujo%2Fangular2_cheatsheet_dart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andresaraujo%2Fangular2_cheatsheet_dart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andresaraujo%2Fangular2_cheatsheet_dart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andresaraujo","download_url":"https://codeload.github.com/andresaraujo/angular2_cheatsheet_dart/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243191443,"owners_count":20251059,"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","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-10-12T08:44:19.146Z","updated_at":"2025-12-26T02:39:42.830Z","avatar_url":"https://github.com/andresaraujo.png","language":null,"funding_links":[],"categories":["Awesome Angular [![Awesome TipeIO](https://img.shields.io/badge/Awesome%20Angular-@TipeIO-6C6AE7.svg)](https://github.com/gdi2290/awesome-angular) [![Awesome devarchy.com](https://img.shields.io/badge/Awesome%20Angular-@devarchy.com-86BDC1.svg)](https://github.com/brillout/awesome-angular-components)","Cheatsheet"],"sub_categories":["Angular \u003ca id=\"angular\"\u003e\u003c/a\u003e"],"readme":"## A WIP Angular 2 cheatsheet for dart (alpha 36)\n\n**Bootstrap angular**\n```dart\nimport 'package:angular2/bootstrap.dart' show bootstrap;\nmain() =\u003e bootstrap(MyApp); //MyApp is a component\n```\n\n**Bootstrap angular with default router**\n```dart\nimport 'package:angular2/angular2.dart' show bind;\nimport 'package:angular2/bootstrap.dart' show bootstrap;\nimport 'package:angular2/router.dart' show APP_BASE_HREF, HashLocationStrategy, LocationStrategy, ROUTER_BINDINGS;\n\nmain() {\n  bootstrap(App, [\n    ROUTER_BINDINGS,\n    bind(APP_BASE_HREF).toValue('/'),\n    // bind(LocationStrategy).toClass(HashLocationStrategy) // if you want to use #\n  ]);\n}\n```\n\n\n### Components\n\n```dart\n@Component(selector: 'selector-name', viewBindings: const [injectables])\n@View(templateUrl: \"home.html\", directives: const [directives])\nclass MyComponent {}\n```\n#### @View\n\n**template**: replace the current element with the contents of the\nHTML string.\n```dart\n//\u003cmy-banner\u003e\u003c/my-banner\u003e\n@Component(selector: 'my-banner')\n@View(template: '\u003cdiv class=\"banner\"\u003e...\u003c/div\u003e')\nclass MyBanner {}\n```\n\n**templateUrl**: replace the current element with the contents loaded by the specified URL\n```dart\n//\u003cmy-banner\u003e\u003c/my-banner\u003e\n@Component(selector: 'my-banner')\n@View(templateUrl: 'package:mypackage/my-banner.html')\nclass MyBanner {}\n```\n```html\n\u003c!-- my-banner.html --\u003e\n\u003cdiv class=\"banner\"\u003e...\u003c/div\u003e\n```\n\n**directives**: Specifies a list of directives that can be used within a template. *Its optional*\n\n**Add Angular core directives (NgFor, NgIf, NgNonBindable, NgSwitch, NgSwitchWhen, NgSwitchDefault)**\n```dart\n@Component(selector: 'my-component')\n@View(templateUrl: \"my-component.html\", directives: const [CORE_DIRECTIVES])\nclass MyComponent {}\n```\n\n**Add directives/components to be used in the template**\n```dart\n@Directive(selector: '[opacity]')\nclass Opacity {/* ... */}\n\n@Component(selector: '[item]')\n@View(templateUrl: \"item.html\")\nclass Item {/* ... */}\n\n@Component(selector: 'my-component')\n@View(templateUrl: \"my-component.html\", directives: const [Opacity, Item])\nclass MyComponent {}\n```\n\n#### @Component\n\n**selector**: The CSS selector that triggers the instantiation of a directive.\n\n   - `element-name`: select by element name.\n   - `.class`: select by class name.\n   - `[attribute]`: select by attribute name.\n   - `[attribute=value]`: select by attribute name and value.\n   - `:not(sub_selector)`: select only if the element does not match the `sub_selector`.\n   - `selector1, selector2`: select if either `selector1` or `selector2` matches.\n\n**Selector example**\n```dart\n//\u003cmy-component\u003e\u003c/my-component\u003e\n@Component(selector: 'my-component')\n@View(templateUrl: \"my-component.html\")\nclass MyComponent {}\n\n//\u003cdiv my-component\u003e\u003c/div\u003e\n@Directive(selector: '[my-component]')\n@View(templateUrl: \"my-component.html\")\nclass MyComponent {}\n```\n\n**Inject dependencies into a component**\n```dart\n@Injectable() //Needed for Angular transformer\nclass MyService {}\n\n@Component(selector: 'selector-name', appInjector: const [MyService])\nclass MyComponent {\n    MyService service;\n    MyComponent(this.service);\n}\n```\n\n**Accesing host DOM element in a component/decorator**\n\n```dart\nimport 'dart:html' as dom;\nimport 'package:angular2/angular2.dart' show Directive, ElementRef;\n\n//\u003cdiv selector-name\u003e\u003c/div\u003e\n@Directive(selector: '[selector-name]')\nclass MyComponent {\n    dom.Element element;\n    MyComponent(ElementRef ref) {\n        element =  ref.nativeElement;\n    }\n}\n```\n\n**properties**: The `properties` property defines a set of `directiveProperty` to `bindingProperty`  key-value pairs. *Its optional*\n   - `directiveProperty` specifies the component property where the value is written.\n   - `bindingProperty` specifies the DOM property where the value is read from.\n\n**Example of properties**\n```dart\n//\u003cmy-component my-name=\"Hodor\" my-desc=\"hooodor?\"\u003e\u003c/my-component\u003e\n@Component(\n    selector: 'my-component', \n    properties: const [\n        'name: my-name',// -\u003e set name(name)\n        'desc: my-desc'\n])\n@View(templateUrl: \"my-component.html\")\nclass MyComponent {\n    String _name;\n    int desc;\n    set name(name) =\u003e _name;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandresaraujo%2Fangular2_cheatsheet_dart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandresaraujo%2Fangular2_cheatsheet_dart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandresaraujo%2Fangular2_cheatsheet_dart/lists"}