3

I know to include internal styles and include external style for a component in Angular 2

import {Component} from 'angular2/core';

@Component({
    selector: 'test',
    templateUrl:'app/test.component.html',
        styleUrls:['app/test.component.css']
})
export class AppComponent {
    carparts = [
    {
        "id": 1,
        "name": "Super Tires",
        "description": "These tires are the very best",
        "inStock": 5
    },
    {
        "id": 2,
        "name": "Reinforced Shocks",
        "description": "Shocks made from kryptonite",
        "inStock": 0
    }];

    totalCarParts(){
        let sum = 0;
        for (let carPart of this.carparts) {
            sum += carPart.inStock;
        }
        return sum;
    }
}

I want to include some common css that could be used over my entire application like normal html.

Is there any angular specific way of doing it or this is the proper way??

2
  • 4
    Place it in the index.html i would say.. :) Commented Jul 14, 2016 at 10:24
  • there is no specific way of doing it in angular right... Commented Jul 14, 2016 at 10:25

2 Answers 2

6

index.html:

<!DOCTYPE html>
<html ng-app="app" ng-controller="AppController">
<head>
    <title>Title</title>
    <link rel="stylesheet" href="styles/sheet.css"/>
</head>
...
Sign up to request clarification or add additional context in comments.

2 Comments

Is this the legal way of achieving it?
This is legal for every HTML framework, and even without a framework. If you add a stylesheet in angular, it simply places the content of that file in the header, so there is no actual difference except this occurs everywhere.
2

Alternatively, there is a src/styles.css file in the standard Angular project fileset. If you add the styles into this, they will be included inline automatically into the of your index.html.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.