angular2实战笔记--组件开发

来源:互联网 发布:惠州乐知英语 编辑:程序博客网 时间:2024/06/06 01:52

一:angular组件开发步骤

1.angular-cli命令行快速生成组件文件:ng g component component_name;

2.在html,css,ts组件文件编写组件视图、样式、数据处理逻辑;



遍历输出数组数据指令:*ngFor="let product of products"







属性绑定

<img [src]="imgUrl">  //控制器内定义 private imgUrl = "http:placehold.it/200x100";

样式绑定

[class.red]="true/false"


父组件传数据给子组件




图片占位:

<img src="http://placehold.it/200x150">