Title: Add html dynamically to an element · Issue #23916 · angular/angular · GitHub
Open Graph Title: Add html dynamically to an element · Issue #23916 · angular/angular
X Title: Add html dynamically to an element · Issue #23916 · angular/angular
Description: I need to dynamically add an html to an element of the template This is the code that I have in my component import { Component, OnInit, ViewChild, TemplateRef } from '@angular/core'; import { HttpClient } from '@angular/common/http'; @C...
Open Graph Description: I need to dynamically add an html to an element of the template This is the code that I have in my component import { Component, OnInit, ViewChild, TemplateRef } from '@angular/core'; import { Http...
X Description: I need to dynamically add an html to an element of the template This is the code that I have in my component import { Component, OnInit, ViewChild, TemplateRef } from '@angular/core'; impor...
Opengraph URL: https://github.com/angular/angular/issues/23916
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add html dynamically to an element","articleBody":"## I need to dynamically add an html to an element of the template\r\nThis is the code that I have in my component\r\n\u003cpre>\r\n\u003ccode>\r\nimport { Component, OnInit, ViewChild, TemplateRef } from '@angular/core';\r\nimport { HttpClient } from '@angular/common/http';\r\n\r\n@Component({\r\n selector: 'app-root',\r\n templateUrl: './app.component.html',\r\n styleUrls: ['./app.component.css']\r\n})\r\nexport class AppComponent {\r\n\r\n private title:string = 'app';\r\n private viewContent:any;\r\n private viewFile:string;\r\n\r\n constructor(private http: HttpClient){}\r\n\r\n ngOnInit(){\r\n \tthis.http.get('assets/views/default.html', {responseType: 'text'}).subscribe(data => {\r\n \tthis.viewFile = 'default.html';\r\n \tthis.viewContent = data;\r\n\t });\r\n }\r\n}\r\n\u003c/code>\u003c/pre>\r\n\r\nThe app.component.html\r\n```html\r\n\u003cdiv style=\"text-align:center\">\r\n \u003ch1>\r\n Welcome to {{ title }}!\r\n \u003c/h1>\r\n \u003cimg width=\"300\" alt=\"Angular Logo\" src=\"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==\">\r\n\u003c/div>\r\n\u003ch2>The next view is load from {{ viewFile }} \u003c/h2>\r\n\r\n\u003cdiv>{{ viewContent }}\u003c/div> ==> this shows: \u003cdiv> Default template {{viewFile}} \u003c/div>\r\n\u003cdiv [innerHTML]=\"viewContent\">\u003c/div> ==> this shows: Default template {{viewFile}}\r\n```\r\n\r\nAnd the file that I want to load that is located in the route: assets/views/default.html\r\n```html\r\n\u003cdiv>\r\n\tDefault template {{viewFile}}\r\n\u003c/div>\r\n```\r\n\r\n## Current behavior\r\n* There is a folder with an html file\r\n* The file is read as text using a get http request\r\n* The content is shown in the template\r\n\r\nThe problem I have is that the content of the html is loaded as text in the template. I could solve that part if I used `[innerHtml]` and passed the contents of the html file, but I have a problem when the file has interpolation variables `{{var}}` because these are not loaded by Angular\r\n\r\n## Expected behavior\r\nDynamically load html files located in a project folder and display them in some element of the template detecting its variables when adding it. The following is what is expected to be displayed in the template when the `viewContent` variable is loaded into some element:\r\n```\r\nDefault template default.html\r\n```\r\n\r\n## Environment\r\n\r\n\u003cpre>\u003ccode>\r\nAngular version: 4.1.3\r\n\r\nBrowser:\r\n- [x ] Safari (desktop) version 11.1\r\n\r\nFor Tooling issues:\r\n- Node version: 8.11.1\r\n- Platform: Mac High Sierra 10.13.4\r\n\u003c/code>\u003c/pre>","author":{"url":"https://github.com/camilo-5972","@type":"Person","name":"camilo-5972"},"datePublished":"2018-05-15T15:22:17Z","url":"https://github.com/angular/angular/issues/23916"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c4c4a4f2-da88-cf8c-c037-ae961f8ac0e8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A210:3F4253:F03170:14046D6:6B010CC9 |
| html-safe-nonce | de7db3092aabaad8e6133c2ab95cd8c7e967c973635d1c1a8b98e23d889b4967 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjEwOjNGNDI1MzpGMDMxNzA6MTQwNDZENjo2QjAxMENDOSIsInZpc2l0b3JfaWQiOiI2MDMyMjU4MjIxNTg1MDA5ODY1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7843995e325d38765188e110d181bde7bb6e40b1a0660478452240649e4a54ad |
| hovercard-subject-tag | issue:323266852 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/23916/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d7b0b831b8abff52a38b9b10ea79ca684fcbdbc033256ac9383e6e787c59ed4a/angular/angular/issues/23916 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d7b0b831b8abff52a38b9b10ea79ca684fcbdbc033256ac9383e6e787c59ed4a/angular/angular/issues/23916 |
| og:image:alt | I need to dynamically add an html to an element of the template This is the code that I have in my component import { Component, OnInit, ViewChild, TemplateRef } from '@angular/core'; import { Http... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | camilo-5972 |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width