Reading a switch value - Angular 2

I am trying to read the value of a switch - in angular 2,

index.html

<input type="radio" id="options1" name="function" value="create">
<input type="radio" id="options2" name="function" value="continue">

index.ts

@Component({
    selector: 'function',
    templateUrl: './client/components/function/index.html',
    styleUrls: ['./client/components/function/index.css'],
    providers: [],
    directives: [ROUTER_DIRECTIVES]
})

I need to display a div in html based on the fact that the value of the radio button is being created or is being continued.

What I tried:

  • Retrieving switch values ​​in typescript file using document.getElementById- Property checkednot found.
  • Reading a value using model.functionby definition modelin typescript. Unable to access the variable model, obviously!
  • I tried to use it [(ngModel)]- it didn’t work either.

Please suggest a twist for this.

+4
source share
1

:

<input type="radio" id="options1" [(ngModel)]="myRadio" value="create">
<input type="radio" id="options2" [(ngModel)]="myRadio" value="continue">

myRadio : myRadio: string = ''

.

javascript DOM Angular2, angular2

+4

Source: https://habr.com/ru/post/1655111/


All Articles