首页 > 其他 > 详细

Angular 使用总结(一)组件

时间:2020-03-22 13:09:24      阅读:56      评论:0      收藏:0      [点我收藏+]

 

生成组件:

ng new component simple-test

 

 

使用模板表达式:

<div [xxx1]="xxx2"></div>

 

 

总结 xxx1:

1. 原生DOM元素本身的 Property,比如 div 元 id 这个Property

<input [(ngModel)]="eleId">
<div [id]="eleId"></div>

 

xxx1 就是 id了

技术分享图片

 

 


 

插一句,经常得干的事,否则用不了 ngModel,赶紧写上好了:

技术分享图片

 

 技术分享图片

 

 


 

 

2. Angular 组件对外暴露的属性

 

子组件暴露一个progress的属性

<div class="parent">
    <div [style.width.%]="progress" class="child"></div>
</div>
  @Input()
  progress:number = 30;

 

 

父组件绑定到的属性,这时候就是子组件暴露的属性,xxx1 就是 progress

Progress:
<input [(ngModel)]="progress"><br><br>
<app-simple-test [progress]="progress | number"></app-simple-test>

 

 

效果:

技术分享图片

 

 技术分享图片

 

 

 

3. 原生DOM元素的 Attribute Class Style

 

Attribute: [attr.xxx]

例子:

col span: <input [(ngModel)]="colSpan">
<table>
    <tr>
        <td>aaa</td>
        <td>bbb</td>
        <td>ccc</td>
    </tr>
    <tr>
        <td [attr.colspan]="colSpan | number">111</td>
    </tr>
</table>

 

注意这句:

技术分享图片

 

Angular 使用总结(一)组件

原文:https://www.cnblogs.com/chenyingzuo/p/12545266.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!