angular4中template语法

本文深入探讨了Angular中表格数据绑定的实现方式,包括属性绑定、事件绑定及双向数据绑定等核心概念。通过具体实例展示了如何利用这些绑定技术来操作DOM元素,实现数据展示和交互功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<table id="example" class="am-table am-table-bordered am-table-striped am-table-hover">
                            <thead>
                            <tr>
                                <th  *ngFor="let colum of colums"  >{{colum.colName}}</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr *ngFor="let parkIn of parkIns" (click)="getDetailAndFind(parkIn[carid])">
                            <td *ngFor="let colum of colums" 
                            width="{{colum.width}}"  [innerHTML]="colum.formatter ? colum.formatter(parkIn[colum.colValue]):parkIn[colum.colValue] "></td>
                            </tr>
                        </tbody>
                    </table>

Binding targets

The target of a data binding is something in the DOM. Depending on the binding type, the target can be an (element | component | directive) property, an (element | component | directive) event, or (rarely) an attribute name. The following table summarizes:

TypeTargetExamples
PropertyElement property
Component property
Directive property
src/app/app.component.html
content_copy<img [src]="heroImageUrl">
<app-hero-detail [hero]="currentHero"></app-hero-detail>
<div [ngClass]="{'special': isSpecial}"></div>
EventElement event
Component event
Directive event
src/app/app.component.html
content_copy<button (click)="onSave()">Save</button>
<app-hero-detail (deleteRequest)="deleteHero()"></app-hero-detail>
<div (myClick)="clicked=$event" clickable>click me</div>
Two-wayEvent and propertysrc/app/app.component.html
content_copy<input [(ngModel)]="name">
AttributeAttribute (the exception)src/app/app.component.html
content_copy<button [attr.aria-label]="help">help</button>
Classclass propertysrc/app/app.component.html
content_copy<div [class.special]="isSpecial">Special</div>
Stylestyle propertysrc/app/app.component.html
content_copy<button [style.color]="isSpecial ? 'red' : 'green'">

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值