3

Based on the documentation found under Angular Component Styles, I was trying to import the style sheets found under the node_modules; ie:

test.component.css:

@import '~@angular/material/core/theming/all-theme.css';

Whereby the component is defined:

@Component({
    moduleId: module.id,
    selector: 'app-test',
    templateUrl: 'test.component.html',
    styleUrls: ['test.component.css'],
    encapsulation: ViewEncapsulation.None
})
export class TestComponent {
}

Unfortunately when browsed to the page, it comes up that the ~@angular/material/core/theming/all-theme.css cannot be found.

This project was set up using the Angular-Cli.

I suppose I could copy in the styles, and reference them that way, but I'd rather keep the library dependencies separate.

2
  • Just to make sure , did you install @angular/material . Is the folder structure correct and file exists in node_modules Commented Jun 10, 2017 at 18:13
  • This looks resolved once I upgraded from angular-cli v1.0.0-beta.28.3 to angular/cli v1.1.2. Commented Jun 17, 2017 at 16:26

2 Answers 2

3

If you want to include any style sheet from node module folder.. you just need to add it in .angular-cli.json

 "styles": [
    "../node_modules/bootstrap/scss/bootstrap.scss"
]

Also you don't need to add encapsulation:ViewEncapsulation.None until you are creating your html dynamically with some third party plugin or adding some random css.

you can always use global css which are included in your .angular-cli.json

Sign up to request clarification or add additional context in comments.

2 Comments

That's correct. You can also import the style in styles.css
It looks like upgrading to a angular-cli v1.1.2 fixed it without needing to modify the .angular-cli.json though I did try that too. I still find that I need to use ViewEncapsulation.None otherwise the classes that are imported are not being resolved when I add them to the element's classList.
-1

The problem is with the file extension. You are using the extension css which doesn't support to import file from the other location better way you can change the extension to the scss. In this you can import the files from the node_modules.

2 Comments

CSS import not supported ?
In webpack when css import any file it is interpreted as the URL and if you use the scss then the file is imported as style-loader. Means it actually load the file not just URL.

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.