{"id":16254159,"url":"https://github.com/sumn2u/angular-cdk-portals","last_synced_at":"2026-04-29T13:35:13.779Z","repository":{"id":92637422,"uuid":"146030133","full_name":"sumn2u/angular-cdk-portals","owner":"sumn2u","description":"Angular CDK portal example","archived":false,"fork":false,"pushed_at":"2019-05-26T11:03:33.000Z","size":325,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-14T08:51:26.615Z","etag":null,"topics":["angular","angular-material","portals","typescript"],"latest_commit_sha":null,"homepage":"https://sumn2u.github.io/angular-cdk-portals/","language":"TypeScript","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/sumn2u.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":"2018-08-24T19:08:12.000Z","updated_at":"2019-05-26T11:02:37.000Z","dependencies_parsed_at":"2023-03-04T23:30:39.330Z","dependency_job_id":null,"html_url":"https://github.com/sumn2u/angular-cdk-portals","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/sumn2u%2Fangular-cdk-portals","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumn2u%2Fangular-cdk-portals/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumn2u%2Fangular-cdk-portals/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumn2u%2Fangular-cdk-portals/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sumn2u","download_url":"https://codeload.github.com/sumn2u/angular-cdk-portals/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247846877,"owners_count":21006090,"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":["angular","angular-material","portals","typescript"],"created_at":"2024-10-10T15:20:14.128Z","updated_at":"2026-04-29T13:35:08.729Z","avatar_url":"https://github.com/sumn2u.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Anguar CDK portals example\n\n###\nView [article](https://medium.com/@sumn2u/dynamic-ui-using-portals-in-angular-cdk-6051988b0f81)\n\n## Prerequisites\nYou will need the following things properly installed on your laptop/pc.\n\n* [Git](http://git-scm.com/)\n* [Node.js](http://nodejs.org/) (with NPM)\n\n## Installing Nodejs via `nvm` [docs](https://github.com/creationix/nvm)\n* **Install Script**\n-`curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash` \n- or `wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash`\n* **Load nvm**\n-`export NVM_DIR=\"$HOME/.nvm\"`\n- `[ -s \"$NVM_DIR/nvm.sh\" ] \u0026\u0026 . \"$NVM_DIR/nvm.sh\"`\n* **Verify Installation**\n- `command -v nvm`\n- `nvm -v`\n* **Download latest node**\n- `nvm install node`\n* **Use Node**\n- `nvm use node`\n\n## Installation\n\n* `git clone \u003crepository-url\u003e` this repository\n*  change into the new directory\n* `npm install`\n\n\n## Running / Development\n\n* `npm start`\n\n\n### Running Tests\n\n* `npm run test`\n\n### Building\n\n* ` npm run build` (production)\n\n### Creating portal \n\n```\nimport {AfterViewInit, ApplicationRef, Component, ComponentFactoryResolver, Injector, OnDestroy, ViewChild} from '@angular/core';\nimport {CdkPortal, DomPortalHost} from '@angular/cdk/portal';\n\n@Component({\n  selector: 'app-action',\n  template: `\n    \u003cng-container *cdkPortal\u003e\n      \u003cng-content\u003e\u003c/ng-content\u003e\n    \u003c/ng-container\u003e\n  `,\n})\nexport class ActionComponent implements AfterViewInit, OnDestroy {\n\n  @ViewChild(CdkPortal) portal;\n  private host: DomPortalHost;\n\n  constructor(\n      private componentFactoryResolver: ComponentFactoryResolver,\n      private applicationRef: ApplicationRef,\n      private injector: Injector\n  ) {\n  }\n\n  ngAfterViewInit(): void {\n    this.host = new DomPortalHost(\n        document.querySelector('#action'),\n        this.componentFactoryResolver,\n        this.applicationRef,\n        this.injector\n    );\n\n    this.host.attach(this.portal);\n  }\n\n  ngOnDestroy(): void {\n    this.host.detach();\n  }\n}\n\n\n\n\n\n@Component({\n  selector: 'app-magic',\n  template: `\n    \u003cng-container *cdkPortal\u003e\n      \u003cng-content\u003e\u003c/ng-content\u003e\n    \u003c/ng-container\u003e\n  `\n})\nexport class ButtonComponent implements AfterViewInit, OnDestroy {\n\n  @ViewChild(CdkPortal) portal: CdkPortal;\n  private host: PortalHost;\n\n  constructor(\n      private cfr: ComponentFactoryResolver,\n      private appRef: ApplicationRef,\n      private injector: Injector,\n  ) {}\n\n  ngAfterViewInit(): void {\n    this.host = new DomPortalHost(\n        document.querySelector('#slot'),\n        this.cfr,\n        this.appRef,\n        this.injector\n    );\n\n    this.host.attach(this.portal);\n  }\n\n  ngOnDestroy() {\n    this.host.detach();\n  }\n}\n\n```\n###\nView [article](https://medium.com/@sumn2u/dynamic-ui-using-portals-in-angular-cdk-6051988b0f81)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsumn2u%2Fangular-cdk-portals","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsumn2u%2Fangular-cdk-portals","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsumn2u%2Fangular-cdk-portals/lists"}