4

I'm using angular 5. Im my module I'm using leaflet 1.2.0.

In leaflet.css I have trouble with images, for example, some css lines:

.leaflet-retina .leaflet-control-layers-toggle {
  background-image: url(/assets/images/leaflet/layers-2x.png);
  background-size: 26px 26px;
}

/* Default icon URLs */
.leaflet-default-icon-path {
  background-image: url(/assets/images/leaflet/marker-icon.png);
}

So, I need to access leaflet.css to its relative route, what I tried:

@Component({
  selector: 'myComponent',
  template:`<div id="myId" class="myClass"></div>`,
   styleUrls: ['./myComponent.component.scss','/../../../../node_modules/leaflet/dist/leaflet.css'],
})

The folder structure:

--project_folder
  --node_modules
     --leaflet
         --dist
           --leaflet.css
  --src
    --app
      --myComponentParent
        --myComponent
          --myComponent.component.ts
          --myComponent.component.scss
          --myComponent.component.html

Can I refer to folder out of src? How can I do it?

2 Answers 2

9

If you are using Angular CLI, you will need to add the Leaflet CSS file to the styles array contained in .angular-cli.json and remove css import from other places

"styles": [
         "styles.css",
        "../node_modules/leaflet/dist/leaflet.css",
]
Sign up to request clarification or add additional context in comments.

2 Comments

Since Angular +6 the .angular-cli.json has baeen replaced by .angular.json file.
what if i want to import it in specifc compoent's .scss
5

No need to add like this. in your angular-cli.json file add style tag with the script path

"styles": [
        "../node_modules/leaflet/dist/leaflet.css",
]

remove the script from your component

styleUrls: ['./myComponent.component.scss'],

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.