Reputation: 2099
I've created a custom web component located in the file: wc-notification.js
and I want to use it in my Angular project built with Angular CLI.
I've included the file in src/index.html
,but I keep getting error:
The resource from “http://localhost:4200/wc-notification.js” was blocked
due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
How to solve this issue?
Upvotes: 1
Views: 623
Reputation: 2099
I've managed to do it the following way:
angular.json
under projects/[my-project-name]/architect/build/options/scripts
I put:"scripts": [
"node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js",
"src/sunpietro-notification.js"
]
app.module.ts
I've imported CUSTOM_ELEMENTS_SCHEMA
: import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
and added that schema to module definition: @NgModule({
declarations: [AppComponent],
imports: [BrowserModule, AppRoutingModule],
providers: [],
bootstrap: [AppComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
Upvotes: 2