Reputation: 1566
I have component with template which have input's tag. I need to set somehow the value to my classes public property.
How to do this?
@Component({
selector: 'delivery-additional-html',
template: `<input type="hidden" #var [value]="'123'"/>`
})
class CustomDeliveryAdditionalHTML implements AfterViewInit {
@Input('var') delivery_extra: any;
ngAfterViewInit()
{
console.log(this.delivery_extra); //Show undefined
}
}
I want to have in this.delivery_extra the "123" value.
Upvotes: 1
Views: 12516
Reputation: 657741
What about
@Input('var') delivery_extra: any = 123;
and then perhaps
template: `<input type="hidden" #var [value]="delivery_extry"/>`
update
@ViewChild('var') myInput:ElementRef;
ngAfterViewInit() {
console.log(this.myInput.nativeElement.value);
}
Upvotes: 5