[Angular 2] Passing data to components with @Input
Angular to with Data input Components
2023-09-14 09:00:55 时间
@Input allows you to pass data into your controller and templates through html and defining custom properties. This allows you to easily reuse components, such as item renderers, and have them display different values for each instance of the renderer.
todoItemRender.ts
import {Input, Component, View} from "angular2/angular2"; @Component({ selector: 'todo-item-render' }) @View({ template: ` <div> <span [content-editable]="todoinput.status === 'started'">{{todoinput.title}}</span> <button (click)="todoinput.toggle()">Toggle</button> </div> ` }) export class TodoItemRender{ @Input() todoinput: TodoModel; }
todoList.ts
import {Component, View, NgFor} from 'angular2/angular2'; import {TodoService} from './todoService'; import {TodoItemRender} from './todoItemRender' @Component({ selector: 'todo-list' }) @View({ directives: [NgFor, TodoItemRender], template: ` <div> <todo-item-render *ng-for="#todo of todoService.todos" [todoinput]="todo" > </todo-item-render> </div> ` }) export class TodoList{ constructor( public todoService:TodoService ){ } }
相关文章
- 怎么组织 Angular 项目 |Top 5 技巧
- 自定义 angular-datetime-picker 格式
- Angular: 最佳实践
- angular子组件传值到父组件_vue子组件传值给父组件
- 如何在Angular项目中使用MQTT
- Angular 里 HTTP 请求和响应结构的拦截器(interceptors)在 SAP Spartacus 中的应用
- Angular面试题_session面试题
- angular面试题及答案_angular面试
- angular 路由懒加载_angular路由
- angular框架发展史
- Angular 项目路径添加指定的访问前缀
- Angular 应用里 ng-package.json 文件的作用是什么?
- 什么是 Angular library 的 secondary entry points?
- ORA-16444: ALTER SYSTEM FLUSH REDO TO STANDBY failed due to a corrupted control file or online log file. ORACLE 报错 故障修复 远程处理
- Angular与React、Vue.js的对比
- Angular 2对 React:究竟孰优孰劣?
- 基于豆瓣API+Angular开发的webApp