I have an angular element, goes with custom tagname - fancy-button
. How can I embed fancy-button
in a angular application?
I have tried the following ways, but none of them worked -
Imported angular-element script in index.html/angular.json[scripts]
and embedded fancy-button
in app.component.html
(root component running in angular application)
Imported angular-element script in app.component.html
and also embedded fancy-button
in app.component.html
(root component running in angular application)
Thanks
To index.html
, I added:
<script type="text/javascript" src="assets/cappapproot.js"></script>
(cappapproot.js
is the name of my Angular Element js)
This caused an Uncaught Error: Zone already loaded.
To resolve this error, in pollyfills.ts
I commented out the line:
import 'zone.js/dist/zone'; // Included with Angular CLI.
in the end, I managed to implement the custom element in my application. You should do the next steps:
angular.json
add the script file in your selected project: ...,
"projects": {
"my-awesome-project": {
...,
"architect": {
"build": {
"options":{
...,
"scripts": [
...,
"[path to your awesome Element js]/[awesome-element].js"
],
...
},
...
},
...
}
In your polyfills
files include import 'zone.js/dist/zone'; // Included with Angular CLI.
at the end of the file.
In the module
you want to include your Angular element
you must add the CUSTOM_ELEMENTS_SCHEMA
in the schemas
parameter of the decorator
:
@NgModule({
declarations: [...],
imports: [
CommonModule,
...
],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With