码迷,mamicode.com
首页 > 其他好文 > 详细

angular 样式属性绑定

时间:2018-04-23 18:33:08      阅读:533      评论:0      收藏:0      [点我收藏+]

标签:temp   ack   red   inpu   als   cli   get   tor   app   

<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;
}

 

angular 样式属性绑定

标签:temp   ack   red   inpu   als   cli   get   tor   app   

原文地址:https://www.cnblogs.com/chenyishi/p/8920367.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!