angular的属性绑定
1. 图片地址属性绑定
html文件
<img [src]="imgUrl">
ts文件
export class ProductComponent implements OnInit {
//声明图片的url地址
private imgUrl = 'http://placehold.it/260x150';
constructor() { }
ngOnInit() {}
}
2. 样式绑定
html文件
//如果star为true则添加glyphicon-star-empty这个类,如果为false则不会添加这个类
<span *ngFor="let star of stars" class="glyphicon glyphicon-star" [class.glyphicon-star-empty]="star"></span>
ts文件
export class StarsComponent implements OnInit {
private stars:boolean[];
constructor() { }
ngOnInit() {
this.stars=[false,false,false,true,true]
}
}
3. 输入属性:父组件的属性传递给子组件
子组件html
<span *ngFor="let star of stars" class="glyphicon glyphicon-star" [class.glyphicon-star-empty]="star"></span>
<span>{{rating}}星</span>
子组件ts文件
import { Component, OnInit ,Input } from '@angular/core';
@Component({
selector: 'app-stars',
templateUrl: './stars.component.html',
styleUrls: ['./stars.component.scss']
})
export class StarsComponent implements OnInit {
//input装饰器,星级评价的组件的rating属性应该由他的父组件传递给它
@Input()
private rating:number = 0;
private stars:boolean[];
constructor() { }
ngOnInit() {
this.stars = [];
for(let i=1;i<=5;i++){
this.stars.push(i>this.rating)
}
}
}
父组件html
<div *ngFor="let product of products" class="col-md-4 col-sm-4 col-lg-4">
<div class="thumbnail">
<img [src]="imgUrl">
<div class="caption">
<h4 class="pull-right">{{product.price}}元</h4>
<h4><a>{{product.title}}</a></h4>
<p>{{product.desc}}</p>
</div>
<div>
//输入属性
<app-stars [rating]="product.star"></app-stars>
</div>
</div>
</div>
angular的属性绑定的更多相关文章
- angular 样式属性绑定
<button (click)="onClick($event)">点我</button> <input type="> <ta ...
- angular HTML属性绑定
- angular Dom属性绑定
- angular 组件学习-组件内属性绑定
#组件内的属性(元素的属性)绑定(property binding) 应用场景:通过改变DOM元素的属性,动态显示/隐藏一个元素 知识点:HTML 属性与DOM属性的区别 改变HTMl属性,浏览器需要 ...
- Angular数据双向绑定
Angular数据双向绑定 AngularJS诞生于2009年,由Misko Hevery 等人创建,后为Google所收购.是一款优秀的前端JS框架,已经被用于Google的多款产品当中.Angul ...
- angular常用属性大全
Angular元素属性大全 addClass()-为每个匹配的元素添加指定的样式类名 after()-在匹配元素集合中的每个元素后面插入参数所指定的内容,作为其兄弟节点 append()-在每个匹配元 ...
- angular 输入属性@Input , 输出属性@Output , 中间人模式
1 输入属性 通常用于父组件向子组件传递信息 举个栗子:我们在父组件向子组件传递股票代码,这里的子组件我们叫它app-order 首先在app.order.component.ts中声明需要由父组件传 ...
- 【WPF】如何把一个枚举属性绑定到多个RadioButton
一.说明 很多时候,我们要把一个枚举的属性的绑定到一组RadioButton上.大家都知道是使用IValueConverter来做,但到底怎么做才好? 而且多个RadioButton的Checked和 ...
- Knockoutjs实例 - 属性绑定(Bindings)之流程控制(Control flow)
一.foreach binding 使用此功能可以方便我们循环遍历输出某个数组.集合中的内容. (1).循环遍历输出数组 View Row Code 1 <script type="t ...
随机推荐
- JEECG环境搭建(Maven版本)-总结Eclipse
1.安装sql server 数据库: 解决办法: 控制面板→程序和功能→启用或关闭Windows功能 .Net Framework 3.5这一项未被完全选中(应为对勾,如果是方块也不可以) 选中该项 ...
- 老生常谈combobox和combotree模糊查询
FIRST /** * combobox和combotree模糊查询 * combotree 结果显示两级父节点(手动设置数量) * 键盘上下键选择叶子节点 * 键盘回车键设置文本的值 */ (fun ...
- linux 下面压缩,解压.rar文件以及rar,unrar实例
http://www.rarlab.com/download.htm [root@bass src]# wget http://www.rarlab.com/rar/rarlinux-x64-5.4. ...
- 进程控制函数(3)-getsid()和setsid()获取当前会话和建立新会话
pid_t setsid(void) 1.调用进程不能是进程组组长,该进程变成新会话首进程(session header) 2.该进程成为一个新进程组的组长进程. 3.需有root权限(ubuntu不 ...
- 452. Remove Linked List Elements【Naive】
Remove all elements from a linked list of integers that have value val. Example Given 1->2->3- ...
- VBA学习笔记(1)----VBA对象属性方法
'VBA对象 'VBA中的对象其实就是我们操作的具有方法.属性的excel中支持的对象 'Excel中的几个常用对象表示方法 '1.工作簿 ' Workbooks 代表工作簿集合,所有的工作簿,Wor ...
- java web 自定义filter
filter顾名思义,过滤器的意思,在javaweb中的Struts就利用了这种机制去实现视图和业务分离. 这里来配置下自己的Filter来理解下Struts的内在. 在web.xml 中添加下面: ...
- 【2015/7/22】SqlServer卸载重装全攻略!
请大家大声地告诉我,哪个软件最恶心. 装了之后跟在电脑里面糊了一层泥,甩都甩不干净.之前手贱,重装系统后装了sqlserver2014的试用版.可惜过了半年试用期就到了.然后重装2012.2014卸载 ...
- CSS3制作文字半透明倒影效果
效果如图.Ps.背景线条是背景图勒,和本文效果无关... html代码如下: <div class="content"> <h3 title="专业 ...
- linux 测试工具
最近在寻找linux的测试工具,试用了一些.记录如下. memtester 内存测试工具,通过对内存进行读写进行测试.可以对同一块空间进行多次的读写. 源码分析 http://www.cnblogs. ...