1

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?

1
  • put the .js in the assets folder, else angular can find it -or import in the main.app.ts- Commented Oct 14, 2019 at 8:50

1 Answer 1

2

I've managed to do it the following way:

  1. In 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"
]
  1. In 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]
})
  1. Started using my custom web component in any component template.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.