zoukankan      html  css  js  c++  java
  • 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{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;
        }
    }
    

      

  • 相关阅读:
    我的暑假周记2018.7.21
    大道至简读后感
    我的暑假周记2018.7.15
    继承与多态
    java联级调用
    古罗马凯撒大帝字串加密
    作业三
    线性同余法产生1000个随机数
    Text2
    java登录界面
  • 原文地址:https://www.cnblogs.com/lihaozhou/p/4677138.html
Copyright © 2011-2022 走看看