There appears to be an issue:
This solution only works for single digit numbers, ranging from 0 to 9, and does not account for two-digit numbers like "10".
If you simply need to find duplicate digits:
In your .ts file, create a new method (or modify an existing one):
inputNumbersString = '';
duplicatesResult = [];
findDuplicates(): void {
const arrOfDigits = Array.from(String(this.inputNumbersString), Number);
this.duplicatesResult = arrOfDigits.filter(
(item, index) => index !== arrOfDigits.indexOf(item)
);
console.log(this.duplicatesResult);
}
Since the input tag returns a string, you must convert it to a number, separate the digits, check for duplicates, and then display them using console.log. Make sure to store the result in the "duplicatesResult" variable for use in your HTML.
In your HTML:
Remove the ng-container and *ngFor that wraps the input, as they will generate unnecessary inputs for each element in the array.
Here is your updated input field and button. Clicking the button will invoke the findDuplicates function. Note that an input value is not required, as all necessary data is already present in the .ts file:
<input [(ngModel)]="inputNumbersString" placeholder="Enter numbers here" />
<button (click)="findDuplicates()">FIND DUPLICATES</button>
<span>{{ duplicatesResult }}</span>
The span tag will display the output.
If desired, you can re-enable the "checked" feature by checking the length of duplicatesResult.