Based on values (A: true, B: true) i need to show radio buttons in angular

I am new to angular. I am trying to show radio buttons (checked and unchecked) based on the server response, checked attribute is not working.

I am trying to show two radio buttons for one label.one radio button is “Allow” and other radio button is “Deny”. Server response be like { “math”: true , “science”: false ,”language” : true}.I need to show ‘Allow’ radio button should be checked for all true values and ‘Deny’ button should be checked for false value. This what I am trying

radio-button.component.html

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><form [formGroup]= subjectGroup (ngsubmit)="onSubmit()">
<div class="form-group row">
<label for="maths" class="col-sm-4 col-form-label text-dark">
<b>Maths</b></label>
<div class="form-check form-check-inline">
<input id="allow" type="radio" value="allow" name="screenCapture" formControlName="mathsValue"(click)="changeValue('maths', true)" checked="'response.maths' == true">
<label for="allow">Allow</label>
</div>
<div class="form-check form-check-inline">
<input id="deny" type="radio" value="deny" name="screenCapture" formControlName="mathsValue" (click)="changeValue('maths', false)"
checked="'response.maths' == false">
<label for="deny">Deny</label>
</div>
</div>
<button class="btn btn-success>Update</button>
</code>
<code><form [formGroup]= subjectGroup (ngsubmit)="onSubmit()"> <div class="form-group row"> <label for="maths" class="col-sm-4 col-form-label text-dark"> <b>Maths</b></label> <div class="form-check form-check-inline"> <input id="allow" type="radio" value="allow" name="screenCapture" formControlName="mathsValue"(click)="changeValue('maths', true)" checked="'response.maths' == true"> <label for="allow">Allow</label> </div> <div class="form-check form-check-inline"> <input id="deny" type="radio" value="deny" name="screenCapture" formControlName="mathsValue" (click)="changeValue('maths', false)" checked="'response.maths' == false"> <label for="deny">Deny</label> </div> </div> <button class="btn btn-success>Update</button> </code>
<form [formGroup]= subjectGroup (ngsubmit)="onSubmit()">
<div class="form-group row">
<label for="maths" class="col-sm-4 col-form-label text-dark">
<b>Maths</b></label>
<div class="form-check form-check-inline">
<input id="allow" type="radio" value="allow" name="screenCapture" formControlName="mathsValue"(click)="changeValue('maths', true)" checked="'response.maths' == true">
<label for="allow">Allow</label>
</div>
<div class="form-check form-check-inline">
<input id="deny" type="radio" value="deny" name="screenCapture" formControlName="mathsValue" (click)="changeValue('maths', false)"
checked="'response.maths' == false">
<label for="deny">Deny</label>
</div>
</div>
<button class="btn btn-success>Update</button>

radio-button.component.ts

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
@Component({
selector: 'app-radio-button',
templateUrl: './radio-button.component.html',
styleUrls: ['./radio-button.component.css']
})
export class RadioButtonComponent implements OnInit {
public response;
public subjectGroup: FormGroup;
ngOnInit(): void {
this.getResponse();
this.form();
}
getResoponse(){
// In this method, I am Storing all the server Response data to global variable (response)
}
form(){
this.subjectGroup = this.fb.group({
maths: new FormControl('')
})
changeValue(e, value) {
(this.response[e]) = value
}
}
</code>
<code>import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; @Component({ selector: 'app-radio-button', templateUrl: './radio-button.component.html', styleUrls: ['./radio-button.component.css'] }) export class RadioButtonComponent implements OnInit { public response; public subjectGroup: FormGroup; ngOnInit(): void { this.getResponse(); this.form(); } getResoponse(){ // In this method, I am Storing all the server Response data to global variable (response) } form(){ this.subjectGroup = this.fb.group({ maths: new FormControl('') }) changeValue(e, value) { (this.response[e]) = value } } </code>
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';

@Component({
  selector: 'app-radio-button',
  templateUrl: './radio-button.component.html',
  styleUrls: ['./radio-button.component.css']
})

export class RadioButtonComponent implements OnInit {
public response;
public subjectGroup: FormGroup;


ngOnInit(): void {
this.getResponse();
this.form();
}

getResoponse(){
 // In this method, I am Storing all the server Response data to global variable (response)
}

form(){
this.subjectGroup = this.fb.group({
maths: new FormControl('')
})

changeValue(e, value) {
(this.response[e]) = value
  }

}

I want to checked allow button to all true values and to checked deny button for all false values, can anyone share the code snippets for this functionality in angular

Your example shows checked="'response.maths' == true".

I suspect if you inspect your DOM, your element will literally have this string in place. If you want angular to evaluate that as an actual code expression, you either need to use [checked] or {{'response.maths' == true}}.

For your usage, neither will actually work, because you’re checking that the string 'response.maths' is true, which it isn’t. (Though you’re doing == rather than === so the whole truthy thing with JS means it probably is true).

What you want to use is much simpler: [checked]="response.maths".

response.maths IS a boolean value, so you can just use it directly.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật