नीचे दिए गए कोड में removeSelectedCountry()
को कॉल किया जाना चाहिए जब स्पैन तत्व क्लिक किया जाता है और handleKeyDown($event)
को div पर एक कीडाउन ईवेंट होने पर कॉल किया जाना चाहिए।कोणीय 2 में कुंजी ट्रिगर पृष्ठ पर किसी भी क्लिक घटना दर्ज करें?
@Component({
selector: "wng-country-picker",
template: `
<ul class="CountryPicker-selected" *ngIf="selectedCountries.length > 0">
<li *ngFor="let country of selectedCountries">
<span class="Pill Pill--primary" (click)="removeSelectedCountry(country)">
{{ country.name }}
</span>
</li>
</ul>
<div (keydown)="handleKeyDown($event)" class="CountryPicker-input"></div>
`,
providers: [CUSTOM_VALUE_ACCESSOR]
})
लेकिन removeSelectedCountry()
हर बार एंटर कुंजी दबाया जाता है।
कोड काम करने के लिए मुझे क्लिक ईवेंट को mousedown
ईवेंट में बदलना पड़ा। यह ठीक काम करता है।
क्या कोई यह समझा सकता है कि क्यों कुंजी कुंजी क्लिक ईवेंट ट्रिगर करेगा?
@Component({
selector: "wng-country-picker",
template: `
<ul class="CountryPicker-selected" *ngIf="selectedCountries.length > 0">
<li *ngFor="let country of selectedCountries">
<span class="Pill Pill--primary" (mousedown)="removeSelectedCountry(country)">
{{ country.name }}
</span>
</li>
</ul>
<div (keydown)="handleKeyDown($event)" class="CountryPicker-input"></div>
`,
providers: [CUSTOM_VALUE_ACCESSOR]
})
ENTER कुंजी के लिए वर्ग snipppet
export class CountryPickerComponent {
private selectedCountries: CountrySummary[] = new Array();
private removeSelectedCountry(country: CountrySummary){
// check if the country exists and remove from selectedCountries
if (this.selectedCountries.filter(ctry => ctry.code === country.code).length > 0)
{
var index = this.selectedCountries.indexOf(country);
this.selectedCountries.splice(index, 1);
this.selectedCountryCodes.splice(index, 1);
}
}
private handleKeyDown(event: any)
{
if (event.keyCode == 13)
{
// action
}
else if (event.keyCode == 40)
{
// action
}
else if (event.keyCode == 38)
{
// action
}
}
क्या आप अपनी कक्षा दिखा सकते हैं? – NEER
मुझे एक ही समस्या का सामना करना पड़ा, "क्या कोई यह समझा सकता है कि क्यों कुंजी कुंजी क्लिक ईवेंट ट्रिगर करेगा?" – Deshak9
** ** ** ** ** पर ** कुंजीपटल ** फ़िल्टरिंग का उपयोग कर मुझे एक ही समस्या है। मेरे परिदृश्य में, ऐसा लगता है कि एक ही प्रतिक्रियाशील प्रपत्र में केवल क्लिक ईवेंट को ट्रिगर करना है। –