Angular2 Use styles in Component

1 内联样式

/**
 * Created by Administrator on 2015/7/23.
 */
import {Component, View, NgIf} from 'angular2/angular2';

@Component({
    selector: 'ng-test',
    properties: ['showElement']
})

@View({
    styles:['div.normal-text{width:100px;height:50px;border:1px solid gray;}'],
    template: `<div class="normal-text">ngff-test</div><div *ng-if="showElement">hide-element</div>`,
    directives: [NgIf]
})

export class NgTest {
    //showElement:boolean;

    constructor() {
        //this.showElement = true;
    }
}

2 外部文件 use styleUrls:['','','']

/**
 * Created by Administrator on 2015/7/23.
 */
import {Component, View, NgIf} from 'angular2/angular2';

@Component({
    selector: 'ng-test',
    properties: ['showElement']
})

@View({
    styleUrls:['../../css/index.css'],
    template: `<div class="normal-text">ngff-test</div><div *ng-if="showElement">hide-element</div>`,
    directives: [NgIf]
})

export class NgTest {
    //showElement:boolean;

    constructor() {
        //this.showElement = true;
    }
}

  

posted @ 2015-07-26 09:30  菠萝君  阅读(431)  评论(0编辑  收藏  举报