zoukankan      html  css  js  c++  java
  • angular 样式属性绑定

    <button (click)="onClick($event)">点我</button>
    <input type="text" (input)="onInput($event)" value="1">
    <table>
      <tr>
        <td [attr.colspan]="colspan" class="a b" [class.c]="isBool"> 你好</td>
      </tr>
    </table>
    
    <table>
      <tr>
        <td [ngClass]="ngClassA"> 你好</td>
      </tr>
    </table>
    
    <table>
      <tr>
        <td [style.color]="isDev ? 'red': 'blue'"> 你好</td>
      </tr>
    </table>
    
    <table>
      <tr>
        <td [style.font-size.em]="isDev ? 3: 1"> 你好</td>
      </tr>
    </table>
    
    <table>
      <tr>
        <td [ngStyle]="ngStyleA"> 你好</td>
      </tr>
    </table>
    import { Component, OnInit } from '@angular/core';
    
    @Component({
      selector: 'app-bind',
      templateUrl: './bind.component.html',
      styleUrls: ['./bind.component.css']
    })
    export class BindComponent implements OnInit {
    
      private colspan = 2;
      private myclass: string;
      private isBool: boolean;
      private ngClassA;
      private isDev = false;
      private ngStyleA;
    
      constructor() { }
    
      ngOnInit() {
        this.ngClassA = {
          a: false,
          b: false,
          c: false
        };
        this.ngStyleA = {
          background: 'yellow',
          color: 'red'
        };
        setTimeout(() => {
          this.isBool = true;
          this.isDev = true;
          this.ngClassA = {
            a: true,
            b: true,
            c: true
          };
          this.ngStyleA = {
            background: 'red',
            color: 'yellow'
          };
        }, 3000);
      }
    
      onClick($event) {
        console.log($event);
      }
      onInput($event) {
        console.log($event.target.value);
        console.log($event.target.getAttribute('value'));
      }
    }
    .a{
        background: yellow;
    }
    .b{
        color: red;
    }
    .c{
        font-size: 20px;
    }
  • 相关阅读:
    BZOJ 1057 悬线法求最大01矩阵
    POJ 2248
    SPOJ
    51NOD
    2017-2018 ACM-ICPC, NEERC, Moscow Subregional Contest J. Judging the Trick
    POJ 1379 模拟退火
    POJ 2420 模拟退火
    Frontend 事后诸葛亮
    【Frontend】Alpha Review 展示博客
    ASE19 团队项目 alpha 阶段 Frontend 组 scrum5 记录
  • 原文地址:https://www.cnblogs.com/chenyishi/p/8920367.html
Copyright © 2011-2022 走看看