We will learn how to make use of the ngStyle directive to directly add multiple style attributes to a DOM element as a style property. We’ll also learn how we can make these styles more dynamic through user input.

import { Component } from '@angular/core';

@Component({
selector: 'ngstyle-component',
template: `
<div [ngStyle]="borderStyle">
Here are some inline styles!
</div> <p>
<input type="text" #boxWidth>
<button (click)="updateStyle(boxWidth.value)">set</button>
</p>
`
})
export class NgStyleComponent {
borderStyle = {
border: '1px solid black',
'border-radius': '3px',
'width.px': 200,
padding: '15px'
}; updateStyle(width) {
this.borderStyle['width.px'] = width;
}
}

Notice that when we use ngStyle, we are able to add '.unit' to the style.

'width.px': 200,

If not useing this syntax, you need to do:

width: '200px'

最新文章

  1. Docker学习---ubuntu环境
  2. Spring1:Spring简介、环境搭建、源码下载及导入MyEclipse
  3. 使用MDK3探测隐藏SSID名称
  4. 源码编译安装screen
  5. Machine Learning : Pre-processing features
  6. redis_查找命令
  7. backbone--部分总结
  8. idea修改jsp后不会自动编译和替换(转)
  9. js中推断对象详细类型
  10. AES加密,解决了同步问题,和随机密钥和固定密钥,多端通信加密不一致解决办法
  11. springmvc.xml或spring.xml 能运行配置文件总是出现错误
  12. 概念学习 - JNDI, JDBC, ODBC, DataSource
  13. SICP-Elements of program
  14. [LeetCode] Complex Number Multiplication 复数相乘
  15. 【leetcode75】Intersection of Two Arrays(数组的交集)
  16. XSS绕过&lt;&gt;进行测试
  17. fiddler 一些不为人知的功能
  18. 插头dp初探
  19. EF 传递的主键值的数量必须与实体上定义的主键值的数量匹配 原因
  20. python基础入门学习简单程序练习

热门文章

  1. QNX与Linux两家未来有望独霸车载电子操作系统
  2. oracle基础入门(二)
  3. 【Henu ACM Round#15 A】 A and B and Chess
  4. cogs 1430. [UVa 11300]分金币
  5. IOS的四种数据存储方式及优劣
  6. KendoUi中KendoDropDownList控件的使用——三级级联模块的实现
  7. OpenCASCADE Job - 武汉中南
  8. SQL Server performance for alter table alter column change data type
  9. sql server 怎样用select语句调用自定义表值函数
  10. mount 命令