[英]Angular: Can I pass values from the console to a component like how a parent component passes a value to its child?
[英]how can I pass a value from parent component to directive in Angular 2?
如果我的父组件中包含以下代码行
<input datepicker type="text" (change)="update($event)"/>
如何将值传递给datepicker指令?
在指令中定义输入
datepicker.directive.ts
import {Input} from '@angular/core';
...
export class DatePickerDirective{
@Input() config:any = {}; //set to default configuration
}
现在,如果您绑定到模板中此指令的config
属性,Angular将传递该值
parent.component.ts
dateConfig:any;
parent.component.html
<input datepicker type="text" [config]="dateConfig"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.