So I have a attribute directive appGetCurrency
in here:
<md-select appGetCurrency [(ngModel)]="value" placeholder="Currency" name="currency">
<md-option *ngFor="let c of currencyList" [value]="c.code">{{c.dsc}}</md-option>
</md-select>
I would like that the appGetCurrency
directive to pass some values to the currencyList
in order to build the list of options.
EDIT
The appGetCurrency
directive just get a list of currencies from a service, then I would like to pass that list to the currencyList
variable in the host template:
@Directive({ selector: '[appGetCurrency]' })
export class CurrencyDirective {
currencies;
constructor() {
// build the <md-options> based on 'currencies'
this.currencies = this.service.getCurrencies('asia');
}
}
You can use an EventEmitter
just like in a component
@Directive({ selector: '[appGetCurrency]' })
export class CurrencyDirective {
@Output() onCurrencyEvent = new EventEmitter();
currencies;
constructor() {
// build the <md-options> based on 'currencies'
this.currencies = this.service.getCurrencies('asia').subscribe((res)=>{
this.onCurrencyEvent.emit(res);
});
}
}
html:
<md-select appGetCurrency [(ngModel)]="value" placeholder="Currency" name="currency" (onCurrencyEvent)="currencyEventOnParent($event)">
Parent component:
currencyEventOnParent(event){
console.log(event);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With