1) create one css file in assets folder that contain common css
both for
component and external window
and give css file path in index.html
or in
angular.json
so that component loads this css.
index.html
<script>document.write('<link href="/assets/css/appstyles.css?v=' + Date.now() + '" rel="stylesheet" />');</script>
assets/css/appstyles.css
.pin-bg {
background: pink;
width: 255px;
height: 20px;
}
2) give css path for external window as:-
this.externalWindow.document.write('<html><head><link rel="stylesheet" type="text/css" href="assets/css/appstyles.css"></head><body>');
window.component.ts
ngOnInit(){
// STEP 4: create an external window
this.externalWindow = window.open('', '', 'width=600,height=400,left=200,top=200');
this.externalWindow.document.write('<html><head><style type="text/css">.pin-bg { background: pink; width:255px; height: 20px;}</style></head><body>');
}
or,
ngOnInit(){
// STEP 4: create an external window
this.externalWindow = window.open('', '', 'width=600,height=400,left=200,top=200');
this.externalWindow.document.write('<html><head><link rel="stylesheet" type="text/css" href="assets/css/appstyles.css"></head><body>');
}
assets/css/appstyles.css
.pin-bg {
background: pink;
width: 255px;
height: 20px;
}
Stackblitz link:-
https://stackblitz.com/edit/angular-open-window-tbd3a4?file=src/app/window.component.ts