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的属性绑定的更多相关文章

  1. angular 样式属性绑定

    <button (click)="onClick($event)">点我</button> <input type="> <ta ...

  2. angular HTML属性绑定

  3. angular Dom属性绑定

  4. angular 组件学习-组件内属性绑定

    #组件内的属性(元素的属性)绑定(property binding) 应用场景:通过改变DOM元素的属性,动态显示/隐藏一个元素 知识点:HTML 属性与DOM属性的区别 改变HTMl属性,浏览器需要 ...

  5. Angular数据双向绑定

    Angular数据双向绑定 AngularJS诞生于2009年,由Misko Hevery 等人创建,后为Google所收购.是一款优秀的前端JS框架,已经被用于Google的多款产品当中.Angul ...

  6. angular常用属性大全

    Angular元素属性大全 addClass()-为每个匹配的元素添加指定的样式类名 after()-在匹配元素集合中的每个元素后面插入参数所指定的内容,作为其兄弟节点 append()-在每个匹配元 ...

  7. angular 输入属性@Input , 输出属性@Output , 中间人模式

    1 输入属性 通常用于父组件向子组件传递信息 举个栗子:我们在父组件向子组件传递股票代码,这里的子组件我们叫它app-order 首先在app.order.component.ts中声明需要由父组件传 ...

  8. 【WPF】如何把一个枚举属性绑定到多个RadioButton

    一.说明 很多时候,我们要把一个枚举的属性的绑定到一组RadioButton上.大家都知道是使用IValueConverter来做,但到底怎么做才好? 而且多个RadioButton的Checked和 ...

  9. Knockoutjs实例 - 属性绑定(Bindings)之流程控制(Control flow)

    一.foreach binding 使用此功能可以方便我们循环遍历输出某个数组.集合中的内容. (1).循环遍历输出数组 View Row Code 1 <script type="t ...

随机推荐

  1. node定时任务——node-schedule模块使用说明

    在实际开发项目中,会遇到很多定时任务的工作.比如:定时导出某些数据.定时发送消息或邮件给用户.定时备份什么类型的文件等等. 一般可以写个定时器,来完成相应的需求,在node.js中自已实现也非常容易, ...

  2. 基于Redis构建10万+终端级的高性能部标JT808协议的Gps网关服务器(转)

    原文地址:http://www.jt808.com/?p=1282 在开发一个大规模的部标GPS监控平台的时候,就算我们花费再多的时间设计和规划,我们也并不能准确的预测出自己未来的车载终端接入量有多大 ...

  3. mybatis的#和$的差别

    在项目中假设使用mybatis保存形如"1,2,3"这种字符串.你须要使用"#"号取值.假设使用$符号会报错, 假设是查询形如"id in (1,2, ...

  4. atitit.自动生成数据库结构脚本,或者更换数据库,基于hibernate4

    atitit.自动生成数据库结构脚本,或者更换数据库,基于hibernate4 目前近况:: 更换数据库,但是是使用spring集成的. <!-- hibernate配置文件路径 --> ...

  5. removeFromParentAndCleanup和callfuncN_selector

    void  removeFromParentAndCleanup (bool cleanup)//删除父节点中的当前节点并清除动作及回调函数 void ActionCallFuncND::onEnte ...

  6. action(一)

    //CCAnimation是封装动画功能的类,它可以看作是由若干个_CCSpriteFrame对象组成的序列,精灵按照顺序切换它们,就形成了动画.CCAnimation也有内存池,    //此处的a ...

  7. jquery的defer

    deferred.promise() 和 .promise() 这两个API语法几乎一样,但是有着很大的差别.deferred.promise()是Deferred实例的一个方法,他返回一个Defer ...

  8. Python 内置模块函数filter reduce

    1.filter()实现过滤的功能 2.reduce()对序列中元素的连续操作可以通过循环来处理 3.map()对tuple元组进行解包操作,调用时设置map()的第一个参数为None 4.使用red ...

  9. 一款纯css3实现的tab选项卡

    今天给大家带来一款纯css3实现的tab选项卡.单击左侧的选项的时候,右侧内容以动画的形式展示.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class=&quo ...

  10. 进一步优化SPA的首屏打开速度(模块化与懒载入) by 嗡

    前言 单页应用的优点在于一次载入全部页面资源,利用本地计算能力渲染页面.提高页面切换速度与用户体验.但缺点在于全部页面资源将被一次性下载完,此时封装出来的静态资源包体积较大,使得第一次打开SPA页面时 ...