Angular 2
घटनाओं का पता लगाना
खोज…
विंडो पर सुनने वाला एक घटक घटना का आकार बदलता है।
मान लीजिए हमारे पास एक घटक है जो एक निश्चित खिड़की की चौड़ाई पर छिपाएगा।
import { Component } from '@angular/core';
@Component({
...
template: `
<div>
<p [hidden]="!visible" (window:resize)="onResize($event)" >Now you see me...</p>
<p>now you dont!</p>
</div>
`
...
})
export class MyComponent {
visible: boolean = false;
breakpoint: number = 768;
constructor() {
}
onResize(event) {
const w = event.target.innerWidth;
if (w >= this.breakpoint) {
this.visible = true;
} else {
// whenever the window is less than 768, hide this component.
this.visible = false;
}
}
}
हमारे टेम्प्लेट में एक p टैग जब भी visible झूठे visible । जब भी onResize इवेंट हैंडलर लागू किया जाता है, तो visible बदल जाएगा। इसका कॉल हर बार window:resize एक घटना में आग लगती है।
Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow