Plunker with a problem that I encountered. "If you comment on the styles in ThirdComponent, you can see how this affects the parent and component styles for the sisters." - adriancarriger (Thanks, Adrian)
In my component I use ...
styles: [' @import "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"; @import "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.43/css/bootstrap-datetimepicker.min.css"; ']
but it seems to ruin the style of any component that causes this. I only need style in this one component. I thought that Angular 2 components were completely independent, they canβt understand why this changes my whole web application.
component:
import { Component, OnInit } from '@angular/core'; import datetimepicker from 'eonasdan-bootstrap-datetimepicker'; import moment from 'moment'; @Component({ selector: 'date-time-picker', styleUrls: ['../../../css/datetimepicker.css'], template:` <div class="input-group"> <input class="form-control" a2e-datetimepicker [date]="date" [options]="a2eOptions" (onChange)="dateChange($event)" (onClick)="dateClick()" /> <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span> </div> ` }) export class DateTimePicker implements OnInit { date: moment.Moment; a2eOptions: any; dateChange(date) { this.date = date; } dateClick() { console.log('click click!') } getTime() { alert('Selected time is:' + this.date); }; addTime(val, selector) { this.date = moment(this.date.add(val, selector)); }; clearTime() { this.date = null; }; constructor(){ this.date = moment(); this.a2eOptions = { format: 'dddd, MMMM Do YYYY, h:mm a',
datetimepicker.css
@import "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"; @import "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.43/css/bootstrap-datetimepicker.min.css";
The same results if I do it as follows:
template:` <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.43/css/bootstrap-datetimepicker.min.css">
Using systemJS
Jus10 source share