Angular2--Directives
来源:互联网 发布:用电脑修改游戏数据 编辑:程序博客网 时间:2024/04/29 20:41
Angular 模版(templates)是动态的. 当Angular 渲染模板时, 会根据directives里的说明来转化成DOM.
一个 directive 就是一个有 @Directive
decorator 的class . 一个 component 是一个 directive + template; 一个 @Component
decorator 实际上是一个有模板的 @Directive
decorator。
While a component is technically a directive, components are so distinctive and central to Angular applications that this architectural overview separates components from directives.
从技术角度来讲,一个 component 就是 一个directive, components 在 Angular 应用中很重要,所以有必要将component和directive区分一下.
存在两种directives: 结构directives 和 属性directives.
通常directives会和属性一样出现在元素标签里,有时是通过name,但更多的是一个声明或绑定的target。
结构 directives 通过增、删、改DOM元素来改变布局。
<li *ngFor="let hero of heroes"></li><app-hero-detail *ngIf="selectedHero"></app-hero-detail>
*ngFor
和 *ngIf
就是结构指令
属性 directives 改变一个已有元素的样式或行为。在模板中看起来很像普通的HTML 属性。
ngModel
directive 声明来一个双向绑定,就是一个属性directive。 ngModel 编辑一个已有元素 (通常是一个 ) 的行为,通过设置它的属性和响应绑定事件。
<input [(ngModel)]="hero.name">
Angular 还有一些可以改变布局的指令 (例如, ngSwitch) 或者修改DOM 元素或者 components (例如, ngStyle and ngClass).
当然你也可以自己写directives 。
angular.io/guide
- Angular2--Directives
- angular2系列教程(四)Attribute directives
- ng2-bootstrap——Native Angular2 directives for Bootstrap
- angular2系列教程(五)Structural directives、再谈组件生命周期
- Correlation Directives -> Directives
- angular2
- angular2
- Angular2
- angular2
- Preprocessor Directives
- References & Directives
- Pragma Directives
- JSP Directives
- #Pragma Directives
- arm directives
- CFI directives
- JSP - Directives
- 定制Directives
- 第四届世界互联网大会人工智能论坛:AI让生活更美好
- pg_ctl: cannot be run as root
- 使用C# 操作了xls 格式的文件!
- xilinx 安装驱动失败或者驱动不适用于该平台解决方案
- 3
- Angular2--Directives
- 【Scikit-Learn 中文文档】无监督降维
- 3
- 写北京SEO优化的方案并不是很难
- IEC62087音视频类设备功耗测量方法
- Sublime Text 3 安装Go语言相关插件gosublime(Linux)
- 驾校类学车网站seo优化案例分析
- find命令使用实例
- 入市有风险,眼红需量力