vijay achary

vijay achary

  • NA
  • 38
  • 1k

How to passing value customdirective to anothere component

Nov 16 2017 1:42 AM
In angular2
================
custom Directive
===============
import { Directive, ElementRef, HostListener, Input,Output,EventEmitter } from '@angular/core';
import { Pipe, PipeTransform } from '@angular/core';
import { DatePipe } from '@angular/common';
@Directive({
selector: '[CustomDirCurrentTime]'
})
export class CustomDirCurrentTime {
@Output() ngModelChange = new EventEmitter();
finalData: string='';
format: string = 'hh:mm';
constructor(private el: ElementRef) {
var datePipe = new DatePipe("en-US");
var Data = datePipe.transform(new Date(), this.format);
-->this.el.nativeElement.value = Data.toString();
this.ngModelChange.emit(this.el.nativeElement.value);
this.el.nativeElement.maxLength = 5;
}
@HostListener('change', ['$event']) onKeyDown(event) {
let GetLegth = this.el.nativeElement.value;
}
}
my component
==========
import { ActivatedRoute } from '@angular/router';
import { FormsModule } from '@angular/forms';
import { Component, OnInit, Input, EventEmitter } from '@angular/core'
@Component({
selector: 'erp-modules',
styleUrls: ['../../../../assets/css/masters/masters.css'],
templateUrl: './ERPModules.html',
})
export class ERPModuleComponent {
@Input() ngModelChange = new EventEmitter();
data: any = [];
Get(e)
{
var kk = this.data;
}
Set()
{
var kkkk = this.data;
}
}
I need custom directive value which is --> marked that is "data" sending my component.how to send from custom directive to my component
 

Answers (2)