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 ...
随机推荐
- API 版本控制的几种方式
个人建议:用content type,即放在Header里面!比如加一个Version:1.4.3 这篇文章写得很好,介绍了三种实现web api版本化的三种方式.我从评论里又收集到两种方式,所以一共 ...
- uploadify onSelect
uploadify onSelect [return false]停止选择 $("#fileEleId").uploadify({ 'width': _option.width, ...
- hdu 2066 一个人的旅行(dijkstra)
一个人的旅行 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- plink参数说明
Plink: command-line connection utilityRelease 0.67Usage: plink [options] [user@]host [command] ...
- Error-Project facet Java version 1.8 is not supported
最近导入最新的Strtus2.5.10.1 Demo时出现了这个错误 解决方案如下: 选中工程——右键——Properties 然后依次展开找到如图所示内容,将1.8改成1.7即可. 原因:工程默认配 ...
- hdoj 1272 小希的迷宫 又一个并查集的简单应用
小希的迷宫 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- Python字符与ASCII码转换
有两个内置函数,记得以前在<Python Cookbook>里看到过. >>>print ord('a') 97 >>>print chr(97) a
- 使用eclipse进行web开发的3个lib文件夹
1.右击project>Build Path>Configure Build Path(一般是在你的项目文件夹中手动创建一个lib文件夹,里面设置若干子文件夹存放不同的jar包,然后通过C ...
- PE框架学习
PE开发基础: 开发平台PowerEngine: 开发新功能: 业务逻辑处理: 1.Transaction:交易 2.Chain:链.责任链 3.Command:命令 4.Template:模板 5. ...
- Eclipse中复制android项目后要改动的地方
1.清单文件中,改package=2.修改包名3.清单文件中app_name F3点进去修改名字