angular attach component to body
JavaScript
import {
Injectable,
Injector,
ComponentFactoryResolver,
EmbeddedViewRef,
ApplicationRef,
ComponentRef
} from '@angular/core';
import { ModalComponent } from './modal.component';
@Injectable({
providedIn: 'root'
})
export class ModalService {
constructor(
private componentFactoryResolver: ComponentFactoryResolver,
private appRef: ApplicationRef,
private injector: Injector
) { }
appendComponentToBody(component: any) {
// Create a component reference from the incoming component
let componentRef = this.componentFactoryResolver
.resolveComponentFactory(component)
.create(this.injector);
// Attach incoming component to the appRef so that it's inside the ng component tree
this.appRef.attachView(componentRef.hostView);
// Get DOM element from incoming component
let contentElem = (componentRef.hostView as EmbeddedViewRef<any>)
.rootNodes[0] as HTMLElement;
// Create a component reference from the service component
let componentRefer = this.componentFactoryResolver
.resolveComponentFactory(ModalComponent)
.create(this.injector);
// Attach component to the appRef so that it's inside the ng component tree
this.appRef.attachView(componentRefer.hostView);
// Get DOM element from service component
let domElem = (componentRefer.hostView as EmbeddedViewRef<any>)
.rootNodes[0] as HTMLElement;
// Append DOM element to the body
document.body.appendChild(domElem);
// Add incoming component to modal component
domElem.querySelector('#Modal').appendChild(contentElem);
}
}
Also in JavaScript:
- Title
- get array by array of indices js
- Category
- JavaScript
- Title
- find substring in string javascript
- Category
- JavaScript
- Title
- flip a coin javascript
- Category
- JavaScript
- Title
- adding cors parameters to extjs ajax
- Category
- JavaScript
- Title
- how to run different node app on server different domains
- Category
- JavaScript
- Title
- get current time epoch javascript
- Category
- JavaScript
- Title
- duplicate encoder
- Category
- JavaScript
- Title
- ionic modal navbar not showing
- Category
- JavaScript
- Title
- command to start api on react
- Category
- JavaScript
- Title
- javascript clear file input
- Category
- JavaScript
- Title
- how to append object in array javascript
- Category
- JavaScript
- Title
- Heroku H10-App Crashed Error
- Category
- JavaScript
- Title
- custom status discord bot
- Category
- JavaScript
- Title
- javascript add function to onchange event
- Category
- JavaScript
- Title
- javascript change web page title
- Category
- JavaScript
- Title
- chart.js line chart
- Category
- JavaScript
- Title
- group all items with same name js
- Category
- JavaScript
- Title
- find intersection between two object arrays javascript
- Category
- JavaScript
- Title
- array index javascript show only first 2 elements
- Category
- JavaScript
- Title
- how to load the images from the website dynamically in react
- Category
- JavaScript
- Title
- get x, y of element js
- Category
- JavaScript
- Title
- Angularjs datetime
- Category
- JavaScript
- Title
- array to comma separated list js
- Category
- JavaScript
- Title
- how to add property to object in javascript
- Category
- JavaScript
- Title
- html get elements by class
- Category
- JavaScript
- Title
- command to create react app
- Category
- JavaScript
- Title
- javascript change attribute
- Category
- JavaScript
- Title
- adding mui theme to index.js
- Category
- JavaScript
- Title
- class javascript
- Category
- JavaScript
- Title
- how to add class to element on mouseclick with js
- Category
- JavaScript
- Title
- how to return the max and min of an array in javascript
- Category
- JavaScript
- Title
- flatten an array in javascript
- Category
- JavaScript
- Title
- bubble sort
- Category
- JavaScript
- Title
- format date js
- Category
- JavaScript
- Title
- average of an array js
- Category
- JavaScript
- Title
- how to add changes every time you route navigate to page in angular
- Category
- JavaScript
- Title
- how to make @click in router-link vuejs
- Category
- JavaScript
- Title
- how to setstate in parent in child component in react native
- Category
- JavaScript
- Title
- how to validate the radio button using jquery
- Category
- JavaScript
- Title
- how to see if a web site is useing react
- Category
- JavaScript
- Title
- cb() never called! npm ERR! This is an error with npm itself.
- Category
- JavaScript
- Title
- for of and for in javascript
- Category
- JavaScript
- Title
- busca binária em javascript
- Category
- JavaScript
- Title
- conditional rendering with radio buttons
- Category
- JavaScript
- Title
- generate bearer token
- Category
- JavaScript
- Title
- javascript advanced concepts
- Category
- JavaScript
- Title
- javascript add minutes to date
- Category
- JavaScript
- Title
- how to create a 30 seconds timer using js
- Category
- JavaScript
- Title
- how to limit characters in number input js
- Category
- JavaScript
- Title
- get the current url javascript
- Category
- JavaScript
- Title
- brute force search javascript
- Category
- JavaScript
- Title
- getelementbyclass
- Category
- JavaScript
- Title
- how to freeze js object
- Category
- JavaScript
- Title
- how to move a block in javascript
- Category
- JavaScript
- Title
- get attribute value jquery
- Category
- JavaScript
- Title
- drupal 8 node has field
- Category
- JavaScript
- Title
- format a date moment
- Category
- JavaScript
- Title
- how to access the second class of an element javascript
- Category
- JavaScript
- Title
- how to make a factorial function in javascript
- Category
- JavaScript
- Title
- inline z-index react
- Category
- JavaScript
- Title
- add and remove class in jquery
- Category
- JavaScript
- Title
- how to add headers to the server response node js
- Category
- JavaScript
- Title
- get data from json using jquery
- Category
- JavaScript
- Title
- async reduce javascript
- Category
- JavaScript
- Title
- array matching
- Category
- JavaScript
- Title
- how to learn javascript
- Category
- JavaScript
- Title
- if else practice javascript
- Category
- JavaScript
- Title
- electron jquery
- Category
- JavaScript
- Title
- how to use chart js in vue js
- Category
- JavaScript
- Title
- convert array object to string javascript
- Category
- JavaScript
- Title
- how to check if a number is even or odd in javascript
- Category
- JavaScript
- Title
- how do you remove a remove element from array in javascript
- Category
- JavaScript
- Title
- eval in js
- Category
- JavaScript
- Title
- http request javascript
- Category
- JavaScript
- Title
- how to remove first character from string in javascript
- Category
- JavaScript
- Title
- difference between React Native and React
- Category
- JavaScript
- Title
- indexof javascript
- Category
- JavaScript
- Title
- beautify json python
- Category
- JavaScript
- Title
- d3 paning
- Category
- JavaScript
- Title
- discord.js tagging the author
- Category
- JavaScript
- Title
- express bodyparser deprecated
- Category
- JavaScript
- Title
- array insertion javascript
- Category
- JavaScript
- Title
- how to paste in input field react native
- Category
- JavaScript
- Title
- graphql yoga access http headers
- Category
- JavaScript
- Title
- angular sumar labels
- Category
- JavaScript
- Title
- include javascript jquery file in html
- Category
- JavaScript
- Title
- document queryselector click event
- Category
- JavaScript
- Title
- how to set height of material ui dialog react
- Category
- JavaScript
- Title
- how to have your discord bot send two message
- Category
- JavaScript
- Title
- events js 292 throw er Unhandled 'error' event ^ Error getaddrinfo ENOTFOUND x86_64-apple-darwin13.4.0 at GetAddrInfoReqWrap.onlookup [as oncomplete]
- Category
- JavaScript
- Title
- add a slash to string in javascript
- Category
- JavaScript
- Title
- how to delete an element from an array in javascript
- Category
- JavaScript
- Title
- cache buster in angular application
- Category
- JavaScript
- Title
- expo open app settings
- Category
- JavaScript
- Title
- data-widget="pushmenu" collable automatically
- Category
- JavaScript
- Title
- clone javascript object
- Category
- JavaScript
- Title
- get the id of a div in jquery
- Category
- JavaScript
- Title
- how to Write a program that simulates a coin toss using random method of Javascript Math class
- Category
- JavaScript
- Title
- add element to body javascript
- Category
- JavaScript
- Title
- ckeditor get instance from textarea
- Category
- JavaScript