Cannot Create Property 'selectedtest' On String 'test1' - Problem With Angular
I want to have multiply active buttons (if selected), and when I click on selected button, I want to remove active class (toggle). How can I do this? If I do it like below, I have
Solution 1:
problem is with your item. You are looping array which contains string values and when you want to select -> selectTest(item), you are providing a string value, which isn't a Object type and doesn't have param 'selectedTest', you should change your array to contain a list of Objects:
this.test = [
{ value: 'test1', isSelected: false },
{ value: 'test1', isSelected: false },
{ value: 'test1', isSelected: false }
];
also change selectTest function to:
selectTest(item) {
item.isSelected = !item.isSelected;
};
then in html change:
<divclass="btn-group"><divclass="btn btn-outline-secondary" *ngFor="let test of tests"
(click)="selectTest(test)"
[ngClass]="{ 'active': test.isSelected }">
{{test.value}}
</div></div>
Post a Comment for "Cannot Create Property 'selectedtest' On String 'test1' - Problem With Angular"