Styles in component for D3.js do not show in angular 2

前端 未结 6 1837
刺人心
刺人心 2020-11-27 03:52

I am using Angular 2 and D3.js. I want to show a red rectangle.

It only works if I put styles in the style.css file. Check this plunkr

When

6条回答
  •  执笔经年
    2020-11-27 04:40

    ViewEncapsulation will fix your problem.

    import {Component,ViewEncapsulation} from 'angular2/core'
    
    @Component({
      selector: 'my-app',
      encapsulation: ViewEncapsulation.None,
      providers: [],
       styles: [`
         .bar {
           fill: red;
        }
      `],
      template: `
        
    `, directives: [] })

提交回复
热议问题