I'm learning Angular 2. For that I'm trying to get the value of an input in the click of a button.
This is my code:
import { Component, Input } from '@angular/core'
import Card from './card.component'
import CardTitle from './cardTitle.component'
import Icon from './icon.component'
import CardDescription from './cardDescription.component'
@Component({
selector: 'jsonTextInput',
templateUrl: '../templates/jsonTextInput.html',
directives: [Card, CardTitle, CardDescription, Icon]
})
export class JsonTextInput {
@Input() ngModel: any;
process () {
console.log(this.ngModel)
alert(1);
}
}
and in the template:
<card class='jsonTextInput'>
<cardtitle
title='Enter your raw json'
>
<icon (click)='process()' name='tick'></icon>
</cardtitle>
<carddescription>Write or paste your json here, and press Process to start navigating</carddescription>
<section class='content'>
<textarea #json [(ngModel)]="json"></textarea>
</section>
</card>
The process is being runned correctly. But the console.log return undefined.
Any idea of how can I read the value of a input on the click of the button?