ngx-gethtml
You can use raw html, javascript, stylesheet in Angular 2+ HTML template with this library.
日本語
English |Installation
npm i ngx-gethtml --save
QuickStart
NgxGetHTMLModule
:
1. Import the Import NgxGetHTMLModule
into AppModule in your Angular project.
;;;
SharedModule
If you use a SharedModule
that you import in multiple other feature modules,
you can export the NgxGetHTMLModule
to make sure you don't have to import it in every module.
<ngx-gethtml>
& <ngx-script>
in HTML template:
2. Use We provide two componets <ngx-gethtml>
& <ngx-script>
to help you add raw HTML and JavaScript in HTML.
You can add mutiple <ngx-gethtml>
& <ngx-script>
tags in a HTML file, but <ngx-script>
must be used in <ngx-gethtml>
.
Example:
Demo <!-- load jQuery --> // use jQuery to log load result. $('#loadResult').html('jQuery loaded successfully.'); // define a function under window object to use it anywhere // do not forget to use the escape {{"{"}} window.test = function() {{"{"}} alert('alert message.'); }; <!-- call function --> Click
Doc
Just a container of <ngx-script>
and other HTML source. All the <ngx-script>
in it will be executed follow the order from top to bottom.
Important! If you have more than one <ngx-gethtml>
tags in a HTML file, they will be executed asynchronously.
Title Some text.
You can add stylesheet import and <style>
in it directly.
- Import JavaScript libiary by using
src
attribute as the same of<script>
. You do not need to addtype="text/javascript"
or any other attributes to it.
- Write JavaScript code inside of
<ngx-script>
directly.
alert('Hello, world!');
- Escape
Because "{" is an Angular template syntax, so you must escape it to {{"{"}}.
Important! Do not escape "}" in you code.
function test() {{"{"}} // some code. }
- The scope of JavaScript variable, function
For security reasons, the variable and function inside of
<ngx-script>
can only use in the scope betweent<ngx-script>
and</ngx-script>
.
If you want to use the variable and function in other<ngx-script>
or in HTML as a event handler, you must define it and attach it to window object.
window.test = function() {{"{"}} alert('alert message.'); }; window.msg = 'some message.' alert(msg); <!-- call function --> Click