3

I have an Angular 5 application in a subdirectory of another parent application.

The parent application is a set of JSP, and other angularJs applications... etc.

What I'm trying to do is include a CSS file, from this parent application, into a component of the Angular 5 application.

@Component({
  selector: 'app-my-form',
  templateUrl: './my-form.component.html',
  styleUrls: [....] //Here
})

Is it possible ?

I looked at this question : Load external css style into Angular 2 Component already asked, but it does not correspond to my case.

Thanks for your help

L Y E S - C H I O U K H
  • 4,765
  • 8
  • 40
  • 57

3 Answers3

5

Try the following:

@Component({
  selector: 'app-my-form',
  templateUrl: './my-form.component.html',
  styleUrls: ['my-form.css']
})

Your file will be a SCSS file: myform.scss.

And then you can import an external css file like this:

@import "my-external-stylesheet.css"; // this on the top of `my-form.scss`
SrAxi
  • 19,787
  • 11
  • 46
  • 65
  • 1
    "What I'm trying to do is include a CSS file, from this parent application, into a component of the Angular 5 application", means that you want to include an external CSS file into an Angular component. Therefore if you include the CSS file to the component's SCSS file... Isn't that what you want? Maybe I'm missing something... – SrAxi Apr 13 '18 at 19:53
3

In the .angular-cli.json file of your child application look for the styles property of your app. Add the path to your parent CSS in there.

Here is an example of the JSON config.

 "apps": [
    {
      "styles": [
        "../../../../apec-template-bootstrap-responsive/src/main/resources/css/old-apec.css",
        "styles.css"
      ],
    }
  ],

This should give your child application any style you require from the parent.

Malcor
  • 2,667
  • 21
  • 29
2

your styleUrls can be the default one:

styleUrls: './my-form.component.css'

while in your my-form.component.css you can import the CSS files you want:

@import ".../component.css";
Gabax
  • 124
  • 2
  • 11