ts(type script)ファイルからチェックボックスのチェック値を取得しようとしています。このために、私はブール変数を持っており、この変数値を使ってdivを表示して隠すことを目的としていますが、私は問題に直面しています。これを解決し、これを行うための正しい方法を私に教えてください。ここに私のコード...プロパティ 'checked'が 'HTMLElement'タイプの角4にありません
htmlコードは、私はその後、私が手に仕えるNG実行すると
**checkbox code**abcde" class="form-check-input" id="abcde" value="1"
(change)="checked('abcde')"> abcde
ショーと非表示のコード
*ngIf='shown'
tsが
checked(value) {
let get_id = document.getElementById('abcde');
if (get_id.checked == true) {
this.shown = true
}
else if (get_id.checked == false)
this.shown = false;
}
ファイルである「プロパティ'checked'はタイプ 'HTMLElement'に存在しません "
ありがとうございます!あなたのコンポーネントここで
import { Component, ViewChild, ElementRef } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
@ViewChild('abcde') abcde: ElementRef;
func(){
this.abcde.nativeElement.checked
}
}
あなたは反応型を使用していますか? –
この 'const get_id = document.getElementById( 'abcde')をHTMLInputElementとして試してください; – yurzui
[コードと再フォーマットされたテキスト](https://stackoverflow.com/editing-help#code)をあなたのサイトに挿入する方法を見てください。質問。あなたの投稿を編集してください。 – fjoe