Insert script tag into Angular 4 HTML Component
I am trying to implement the HTML5 version of the PhotoeditorSDK from this website - https://docs.photoeditorsdk.com/guides/html5/v4/introduction/getting_started
I have tried to implement using the Angular Github repo but it would seem that package.json illustrate this only works for Angular 5 & 6 and our app currently is a little outdated being Angular 4.x (and we cannot upgrade to 5 at this time)
Using the HTML5 method is fairly easy in a simple application but within an Angular 4 this seems to be tricky as due to Angular restrictions I am unable to use <script> tags within the component.
In the index <head> I have added the following:
<head>
<!-- React Dependencies for the SDK UI -->
<script src="js/vendor/react.production.min.js"></script>
<script src="js/vendor/react-dom.production.min.js"></script>
<!-- PhotoEditor SDK-->
<script src="js/PhotoEditorSDK.min.js"></script>
<!-- PhotoEditor SDK UI -->
<script src="js/PhotoEditorSDK.UI.DesktopUI.min.js"></script>
<link rel="stylesheet" href="css/PhotoEditorSDK.UI.DesktopUI.min.css"/>
</head>
In the template itself there is a simple <div> as follows :
<div id="editor" style="width: 100vw; height: 100vh;"></div>
The script tag itself looks as following - and would basically attach an image that would show within the editor to edit etc..
<script>
window.onload = function () {
var image = new Image()
image.onload = function () {
var container = document.getElementById('editor')
var editor = new PhotoEditorSDK.UI.DesktopUI({
container: container,
// Please replace this with your license: https://www.photoeditorsdk.com/dashboard/subscriptions
license: '{"owner":"Imgly Inc.","version":"2.1", ...}',
editor: {
image: image
},
assets: {
// This should be the absolute path to your `assets` directory
baseUrl: '/assets'
}
})
}
image.src = './example.jpg'
}
</script>
I am trying to figure out the best way to use <script> above directly within an Angular 4 Component - I know this is best practice but what is the best way to do this?
javascript angular html5 photoeditorsdk
add a comment |
I am trying to implement the HTML5 version of the PhotoeditorSDK from this website - https://docs.photoeditorsdk.com/guides/html5/v4/introduction/getting_started
I have tried to implement using the Angular Github repo but it would seem that package.json illustrate this only works for Angular 5 & 6 and our app currently is a little outdated being Angular 4.x (and we cannot upgrade to 5 at this time)
Using the HTML5 method is fairly easy in a simple application but within an Angular 4 this seems to be tricky as due to Angular restrictions I am unable to use <script> tags within the component.
In the index <head> I have added the following:
<head>
<!-- React Dependencies for the SDK UI -->
<script src="js/vendor/react.production.min.js"></script>
<script src="js/vendor/react-dom.production.min.js"></script>
<!-- PhotoEditor SDK-->
<script src="js/PhotoEditorSDK.min.js"></script>
<!-- PhotoEditor SDK UI -->
<script src="js/PhotoEditorSDK.UI.DesktopUI.min.js"></script>
<link rel="stylesheet" href="css/PhotoEditorSDK.UI.DesktopUI.min.css"/>
</head>
In the template itself there is a simple <div> as follows :
<div id="editor" style="width: 100vw; height: 100vh;"></div>
The script tag itself looks as following - and would basically attach an image that would show within the editor to edit etc..
<script>
window.onload = function () {
var image = new Image()
image.onload = function () {
var container = document.getElementById('editor')
var editor = new PhotoEditorSDK.UI.DesktopUI({
container: container,
// Please replace this with your license: https://www.photoeditorsdk.com/dashboard/subscriptions
license: '{"owner":"Imgly Inc.","version":"2.1", ...}',
editor: {
image: image
},
assets: {
// This should be the absolute path to your `assets` directory
baseUrl: '/assets'
}
})
}
image.src = './example.jpg'
}
</script>
I am trying to figure out the best way to use <script> above directly within an Angular 4 Component - I know this is best practice but what is the best way to do this?
javascript angular html5 photoeditorsdk
1
That's not best practice at all ! the best practice is to save a .js file in yourassetsfolder and declare this script in theangular-cli.json(orangular.jsonin the newest versions) so that it gets imported at build time.
– trichetriche
Nov 13 '18 at 15:12
add a comment |
I am trying to implement the HTML5 version of the PhotoeditorSDK from this website - https://docs.photoeditorsdk.com/guides/html5/v4/introduction/getting_started
I have tried to implement using the Angular Github repo but it would seem that package.json illustrate this only works for Angular 5 & 6 and our app currently is a little outdated being Angular 4.x (and we cannot upgrade to 5 at this time)
Using the HTML5 method is fairly easy in a simple application but within an Angular 4 this seems to be tricky as due to Angular restrictions I am unable to use <script> tags within the component.
In the index <head> I have added the following:
<head>
<!-- React Dependencies for the SDK UI -->
<script src="js/vendor/react.production.min.js"></script>
<script src="js/vendor/react-dom.production.min.js"></script>
<!-- PhotoEditor SDK-->
<script src="js/PhotoEditorSDK.min.js"></script>
<!-- PhotoEditor SDK UI -->
<script src="js/PhotoEditorSDK.UI.DesktopUI.min.js"></script>
<link rel="stylesheet" href="css/PhotoEditorSDK.UI.DesktopUI.min.css"/>
</head>
In the template itself there is a simple <div> as follows :
<div id="editor" style="width: 100vw; height: 100vh;"></div>
The script tag itself looks as following - and would basically attach an image that would show within the editor to edit etc..
<script>
window.onload = function () {
var image = new Image()
image.onload = function () {
var container = document.getElementById('editor')
var editor = new PhotoEditorSDK.UI.DesktopUI({
container: container,
// Please replace this with your license: https://www.photoeditorsdk.com/dashboard/subscriptions
license: '{"owner":"Imgly Inc.","version":"2.1", ...}',
editor: {
image: image
},
assets: {
// This should be the absolute path to your `assets` directory
baseUrl: '/assets'
}
})
}
image.src = './example.jpg'
}
</script>
I am trying to figure out the best way to use <script> above directly within an Angular 4 Component - I know this is best practice but what is the best way to do this?
javascript angular html5 photoeditorsdk
I am trying to implement the HTML5 version of the PhotoeditorSDK from this website - https://docs.photoeditorsdk.com/guides/html5/v4/introduction/getting_started
I have tried to implement using the Angular Github repo but it would seem that package.json illustrate this only works for Angular 5 & 6 and our app currently is a little outdated being Angular 4.x (and we cannot upgrade to 5 at this time)
Using the HTML5 method is fairly easy in a simple application but within an Angular 4 this seems to be tricky as due to Angular restrictions I am unable to use <script> tags within the component.
In the index <head> I have added the following:
<head>
<!-- React Dependencies for the SDK UI -->
<script src="js/vendor/react.production.min.js"></script>
<script src="js/vendor/react-dom.production.min.js"></script>
<!-- PhotoEditor SDK-->
<script src="js/PhotoEditorSDK.min.js"></script>
<!-- PhotoEditor SDK UI -->
<script src="js/PhotoEditorSDK.UI.DesktopUI.min.js"></script>
<link rel="stylesheet" href="css/PhotoEditorSDK.UI.DesktopUI.min.css"/>
</head>
In the template itself there is a simple <div> as follows :
<div id="editor" style="width: 100vw; height: 100vh;"></div>
The script tag itself looks as following - and would basically attach an image that would show within the editor to edit etc..
<script>
window.onload = function () {
var image = new Image()
image.onload = function () {
var container = document.getElementById('editor')
var editor = new PhotoEditorSDK.UI.DesktopUI({
container: container,
// Please replace this with your license: https://www.photoeditorsdk.com/dashboard/subscriptions
license: '{"owner":"Imgly Inc.","version":"2.1", ...}',
editor: {
image: image
},
assets: {
// This should be the absolute path to your `assets` directory
baseUrl: '/assets'
}
})
}
image.src = './example.jpg'
}
</script>
I am trying to figure out the best way to use <script> above directly within an Angular 4 Component - I know this is best practice but what is the best way to do this?
javascript angular html5 photoeditorsdk
javascript angular html5 photoeditorsdk
asked Nov 13 '18 at 15:09
ZabsZabs
5,48138126218
5,48138126218
1
That's not best practice at all ! the best practice is to save a .js file in yourassetsfolder and declare this script in theangular-cli.json(orangular.jsonin the newest versions) so that it gets imported at build time.
– trichetriche
Nov 13 '18 at 15:12
add a comment |
1
That's not best practice at all ! the best practice is to save a .js file in yourassetsfolder and declare this script in theangular-cli.json(orangular.jsonin the newest versions) so that it gets imported at build time.
– trichetriche
Nov 13 '18 at 15:12
1
1
That's not best practice at all ! the best practice is to save a .js file in your
assets folder and declare this script in the angular-cli.json (or angular.json in the newest versions) so that it gets imported at build time.– trichetriche
Nov 13 '18 at 15:12
That's not best practice at all ! the best practice is to save a .js file in your
assets folder and declare this script in the angular-cli.json (or angular.json in the newest versions) so that it gets imported at build time.– trichetriche
Nov 13 '18 at 15:12
add a comment |
1 Answer
1
active
oldest
votes
Your component has an element with id editor. This will only be available in the ngAfterViewInit hook of the component. Once this is called, the window.onload has been called ages ago. Also when the onload is called, the element doesn't exist at all yet, so it's also a bad idea to put it there.
Best would be to call the method from inside the ngAfterViewInit of your component, and use the @ViewChild annotation:
declare const PhotoEditorSDK: any;
@Component({
template: `<div style="width: 100vw; height: 100vh;" #editor></div>`
})
export class EditorComponent implements AfterViewInit {
@ViewChild('editor') editor: ElementRef<HTMLElement>;
ngAfterViewInit(): void {
const image = new Image();
image.addEventListener('load', () => {
const editor = new PhotoEditorSDK.UI.DesktopUI({
container: this.editor.nativeElement,
license: '{"owner":"Imgly Inc.","version":"2.1", ...}',
editor: {
image
},
assets: {
baseUrl: '/assets'
}
});
});
image.src = './example.jpg'
}
}
thanks @Pierre - that is making more sense now, the error I see now is that thePhotoEditorSDKcannot be found (these are loaded within the index.html) but I presume Angular 4 requires this to be loaded differently - how would this work?
– Zabs
Nov 13 '18 at 15:31
If you are sure they are loaded, you need to add adeclare const PhotoEditorSDK: any;I'll update my answer. It would be best if they have typings though
– PierreDuc
Nov 13 '18 at 15:33
Sorry my fault - I can see the PhotoEditorSDK when I view it directly within the console but when I runng serveto rebuild the app I get the error :Cannot find name 'PhotoEditorSDK'- I added the component in the gist below if that helps :) gist.github.com/gkimpson/cd36b6278169f0e7e3af32c810ef87b1
– Zabs
Nov 13 '18 at 16:01
I will play around with this a bit more and come back to this thread later as it is almost there and you advice has put me in the right direction :)
– Zabs
Nov 13 '18 at 16:06
1
@Zabs perhaps the image doesn't load because you did not add it your assets folder. Is there are 404 in the network request tab for that image? I believe it won't fire aloadevent if there is a 404. But good that it works now :)
– PierreDuc
Nov 14 '18 at 14:08
|
show 4 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283974%2finsert-script-tag-into-angular-4-html-component%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your component has an element with id editor. This will only be available in the ngAfterViewInit hook of the component. Once this is called, the window.onload has been called ages ago. Also when the onload is called, the element doesn't exist at all yet, so it's also a bad idea to put it there.
Best would be to call the method from inside the ngAfterViewInit of your component, and use the @ViewChild annotation:
declare const PhotoEditorSDK: any;
@Component({
template: `<div style="width: 100vw; height: 100vh;" #editor></div>`
})
export class EditorComponent implements AfterViewInit {
@ViewChild('editor') editor: ElementRef<HTMLElement>;
ngAfterViewInit(): void {
const image = new Image();
image.addEventListener('load', () => {
const editor = new PhotoEditorSDK.UI.DesktopUI({
container: this.editor.nativeElement,
license: '{"owner":"Imgly Inc.","version":"2.1", ...}',
editor: {
image
},
assets: {
baseUrl: '/assets'
}
});
});
image.src = './example.jpg'
}
}
thanks @Pierre - that is making more sense now, the error I see now is that thePhotoEditorSDKcannot be found (these are loaded within the index.html) but I presume Angular 4 requires this to be loaded differently - how would this work?
– Zabs
Nov 13 '18 at 15:31
If you are sure they are loaded, you need to add adeclare const PhotoEditorSDK: any;I'll update my answer. It would be best if they have typings though
– PierreDuc
Nov 13 '18 at 15:33
Sorry my fault - I can see the PhotoEditorSDK when I view it directly within the console but when I runng serveto rebuild the app I get the error :Cannot find name 'PhotoEditorSDK'- I added the component in the gist below if that helps :) gist.github.com/gkimpson/cd36b6278169f0e7e3af32c810ef87b1
– Zabs
Nov 13 '18 at 16:01
I will play around with this a bit more and come back to this thread later as it is almost there and you advice has put me in the right direction :)
– Zabs
Nov 13 '18 at 16:06
1
@Zabs perhaps the image doesn't load because you did not add it your assets folder. Is there are 404 in the network request tab for that image? I believe it won't fire aloadevent if there is a 404. But good that it works now :)
– PierreDuc
Nov 14 '18 at 14:08
|
show 4 more comments
Your component has an element with id editor. This will only be available in the ngAfterViewInit hook of the component. Once this is called, the window.onload has been called ages ago. Also when the onload is called, the element doesn't exist at all yet, so it's also a bad idea to put it there.
Best would be to call the method from inside the ngAfterViewInit of your component, and use the @ViewChild annotation:
declare const PhotoEditorSDK: any;
@Component({
template: `<div style="width: 100vw; height: 100vh;" #editor></div>`
})
export class EditorComponent implements AfterViewInit {
@ViewChild('editor') editor: ElementRef<HTMLElement>;
ngAfterViewInit(): void {
const image = new Image();
image.addEventListener('load', () => {
const editor = new PhotoEditorSDK.UI.DesktopUI({
container: this.editor.nativeElement,
license: '{"owner":"Imgly Inc.","version":"2.1", ...}',
editor: {
image
},
assets: {
baseUrl: '/assets'
}
});
});
image.src = './example.jpg'
}
}
thanks @Pierre - that is making more sense now, the error I see now is that thePhotoEditorSDKcannot be found (these are loaded within the index.html) but I presume Angular 4 requires this to be loaded differently - how would this work?
– Zabs
Nov 13 '18 at 15:31
If you are sure they are loaded, you need to add adeclare const PhotoEditorSDK: any;I'll update my answer. It would be best if they have typings though
– PierreDuc
Nov 13 '18 at 15:33
Sorry my fault - I can see the PhotoEditorSDK when I view it directly within the console but when I runng serveto rebuild the app I get the error :Cannot find name 'PhotoEditorSDK'- I added the component in the gist below if that helps :) gist.github.com/gkimpson/cd36b6278169f0e7e3af32c810ef87b1
– Zabs
Nov 13 '18 at 16:01
I will play around with this a bit more and come back to this thread later as it is almost there and you advice has put me in the right direction :)
– Zabs
Nov 13 '18 at 16:06
1
@Zabs perhaps the image doesn't load because you did not add it your assets folder. Is there are 404 in the network request tab for that image? I believe it won't fire aloadevent if there is a 404. But good that it works now :)
– PierreDuc
Nov 14 '18 at 14:08
|
show 4 more comments
Your component has an element with id editor. This will only be available in the ngAfterViewInit hook of the component. Once this is called, the window.onload has been called ages ago. Also when the onload is called, the element doesn't exist at all yet, so it's also a bad idea to put it there.
Best would be to call the method from inside the ngAfterViewInit of your component, and use the @ViewChild annotation:
declare const PhotoEditorSDK: any;
@Component({
template: `<div style="width: 100vw; height: 100vh;" #editor></div>`
})
export class EditorComponent implements AfterViewInit {
@ViewChild('editor') editor: ElementRef<HTMLElement>;
ngAfterViewInit(): void {
const image = new Image();
image.addEventListener('load', () => {
const editor = new PhotoEditorSDK.UI.DesktopUI({
container: this.editor.nativeElement,
license: '{"owner":"Imgly Inc.","version":"2.1", ...}',
editor: {
image
},
assets: {
baseUrl: '/assets'
}
});
});
image.src = './example.jpg'
}
}
Your component has an element with id editor. This will only be available in the ngAfterViewInit hook of the component. Once this is called, the window.onload has been called ages ago. Also when the onload is called, the element doesn't exist at all yet, so it's also a bad idea to put it there.
Best would be to call the method from inside the ngAfterViewInit of your component, and use the @ViewChild annotation:
declare const PhotoEditorSDK: any;
@Component({
template: `<div style="width: 100vw; height: 100vh;" #editor></div>`
})
export class EditorComponent implements AfterViewInit {
@ViewChild('editor') editor: ElementRef<HTMLElement>;
ngAfterViewInit(): void {
const image = new Image();
image.addEventListener('load', () => {
const editor = new PhotoEditorSDK.UI.DesktopUI({
container: this.editor.nativeElement,
license: '{"owner":"Imgly Inc.","version":"2.1", ...}',
editor: {
image
},
assets: {
baseUrl: '/assets'
}
});
});
image.src = './example.jpg'
}
}
edited Nov 13 '18 at 15:33
answered Nov 13 '18 at 15:20
PierreDucPierreDuc
29.3k45376
29.3k45376
thanks @Pierre - that is making more sense now, the error I see now is that thePhotoEditorSDKcannot be found (these are loaded within the index.html) but I presume Angular 4 requires this to be loaded differently - how would this work?
– Zabs
Nov 13 '18 at 15:31
If you are sure they are loaded, you need to add adeclare const PhotoEditorSDK: any;I'll update my answer. It would be best if they have typings though
– PierreDuc
Nov 13 '18 at 15:33
Sorry my fault - I can see the PhotoEditorSDK when I view it directly within the console but when I runng serveto rebuild the app I get the error :Cannot find name 'PhotoEditorSDK'- I added the component in the gist below if that helps :) gist.github.com/gkimpson/cd36b6278169f0e7e3af32c810ef87b1
– Zabs
Nov 13 '18 at 16:01
I will play around with this a bit more and come back to this thread later as it is almost there and you advice has put me in the right direction :)
– Zabs
Nov 13 '18 at 16:06
1
@Zabs perhaps the image doesn't load because you did not add it your assets folder. Is there are 404 in the network request tab for that image? I believe it won't fire aloadevent if there is a 404. But good that it works now :)
– PierreDuc
Nov 14 '18 at 14:08
|
show 4 more comments
thanks @Pierre - that is making more sense now, the error I see now is that thePhotoEditorSDKcannot be found (these are loaded within the index.html) but I presume Angular 4 requires this to be loaded differently - how would this work?
– Zabs
Nov 13 '18 at 15:31
If you are sure they are loaded, you need to add adeclare const PhotoEditorSDK: any;I'll update my answer. It would be best if they have typings though
– PierreDuc
Nov 13 '18 at 15:33
Sorry my fault - I can see the PhotoEditorSDK when I view it directly within the console but when I runng serveto rebuild the app I get the error :Cannot find name 'PhotoEditorSDK'- I added the component in the gist below if that helps :) gist.github.com/gkimpson/cd36b6278169f0e7e3af32c810ef87b1
– Zabs
Nov 13 '18 at 16:01
I will play around with this a bit more and come back to this thread later as it is almost there and you advice has put me in the right direction :)
– Zabs
Nov 13 '18 at 16:06
1
@Zabs perhaps the image doesn't load because you did not add it your assets folder. Is there are 404 in the network request tab for that image? I believe it won't fire aloadevent if there is a 404. But good that it works now :)
– PierreDuc
Nov 14 '18 at 14:08
thanks @Pierre - that is making more sense now, the error I see now is that the
PhotoEditorSDK cannot be found (these are loaded within the index.html) but I presume Angular 4 requires this to be loaded differently - how would this work?– Zabs
Nov 13 '18 at 15:31
thanks @Pierre - that is making more sense now, the error I see now is that the
PhotoEditorSDK cannot be found (these are loaded within the index.html) but I presume Angular 4 requires this to be loaded differently - how would this work?– Zabs
Nov 13 '18 at 15:31
If you are sure they are loaded, you need to add a
declare const PhotoEditorSDK: any; I'll update my answer. It would be best if they have typings though– PierreDuc
Nov 13 '18 at 15:33
If you are sure they are loaded, you need to add a
declare const PhotoEditorSDK: any; I'll update my answer. It would be best if they have typings though– PierreDuc
Nov 13 '18 at 15:33
Sorry my fault - I can see the PhotoEditorSDK when I view it directly within the console but when I run
ng serve to rebuild the app I get the error : Cannot find name 'PhotoEditorSDK' - I added the component in the gist below if that helps :) gist.github.com/gkimpson/cd36b6278169f0e7e3af32c810ef87b1– Zabs
Nov 13 '18 at 16:01
Sorry my fault - I can see the PhotoEditorSDK when I view it directly within the console but when I run
ng serve to rebuild the app I get the error : Cannot find name 'PhotoEditorSDK' - I added the component in the gist below if that helps :) gist.github.com/gkimpson/cd36b6278169f0e7e3af32c810ef87b1– Zabs
Nov 13 '18 at 16:01
I will play around with this a bit more and come back to this thread later as it is almost there and you advice has put me in the right direction :)
– Zabs
Nov 13 '18 at 16:06
I will play around with this a bit more and come back to this thread later as it is almost there and you advice has put me in the right direction :)
– Zabs
Nov 13 '18 at 16:06
1
1
@Zabs perhaps the image doesn't load because you did not add it your assets folder. Is there are 404 in the network request tab for that image? I believe it won't fire a
load event if there is a 404. But good that it works now :)– PierreDuc
Nov 14 '18 at 14:08
@Zabs perhaps the image doesn't load because you did not add it your assets folder. Is there are 404 in the network request tab for that image? I believe it won't fire a
load event if there is a 404. But good that it works now :)– PierreDuc
Nov 14 '18 at 14:08
|
show 4 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283974%2finsert-script-tag-into-angular-4-html-component%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
That's not best practice at all ! the best practice is to save a .js file in your
assetsfolder and declare this script in theangular-cli.json(orangular.jsonin the newest versions) so that it gets imported at build time.– trichetriche
Nov 13 '18 at 15:12