angular5之DOM绑定和html绑定

1)DOM绑定
(一般是事件绑定)

html
<input   value='tom'  (input)="doInput($event)"></input>
component
doInput(event:any){
		console.log(event.target.value)
}

2)html绑定
(一般是class,style,attr属性绑定)

(-----------------------------属性绑定-----------------------------------------)
html中------
			 <div>
			   <table>
			     <tr>
			       <td [attr.collapse]="size">html属性绑定</td>   //给td绑定collapse属性
			       <td>html属性绑定</td>
			     </tr>
			   </table>
			  </div>
component中-----
		size=3;
  (---------------------class绑定-----------------------------------------)
  html中-------
 <p [class]="divClass"> class全部属性绑定 </p>
 <p class='bg fontSize' [class.colorStyle]='isTrue'>class属性部分绑定</p>
 <p  [ngClass]='ngClassStyle'>使用[ngClass]绑定属性</p>
 css中------
.bg{ background:blue;}
.fontSize:{ font-size:20px;}
.colorStyle{ color:red}

component中------
ngClassStyle:any={
	bg:false,
	colorStyle:false,
	fontSize:false
}
isTrue:boolean=false;
	constuctor(){
			setTimeout(()=>{
				this.divClass = ''bg fontSize colorStyle"
				this.isTrue=true;
				this.ngClassStyle={
					bg:true,
					fontSize:true,
					colorStyle:true
					}
		     },3000)
	}
	
  (style绑定)
  <p [style.color]="isDev?'red':'green'">1111</p>
  <p [style.font-size.em]="isDev?'2':'3'">222</p>
  <p [ngStyle]='isStyle'>3333</p>
  component中------
	  isStyle:any={
	  		fontSize:'19px',
	  		color:'red',
	  		background:'yellow'
		}
		

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值