मेरे पास यह कोड HTML फ़ाइल में है। बेशक how to trigger click event of input file from button click in angular 2? यह काम किया:ईवेंट ट्रिगर कैसे करें इनपुट प्रकार = "फ़ाइल" पर कोणीय 2 में फ़ंक्शन द्वारा क्लिक करें?
<input #fileInput type="file" />
demo.ts
import {
Component,
Inject,
OnInit,
ElementRef,
Renderer,
ViewQuery
} from '@angular/core';
@Component({
selector: 'demo',
templateUrl: 'client/dev/demo/demo.html',
})
export class DemoComponent implements OnInit{
@ViewQuery('fileInput') fileInput:ElementRef;
constructor(){}
triggerFile(){
// do something
// trigger input type="file" here
this.fileInput.nativeElement.click();
}
ngOnInit() {
}
}
मैं इस सवाल का जवाब देखें। लेकिन मैं ट्रिगरफाइल() फ़ंक्शन में इनपुट प्रकार = "फ़ाइल" ट्रिगर करना चाहता हूं और मैं ViewQuery और nativeElement.click() फ़ंक्शन का उपयोग करता हूं। लेकिन यह इस त्रुटि को कंसोल करता है "अपरिभाषित की मूल संपत्ति 'मूल' पढ़ नहीं सकता '। मैं angular2 आरसी 1 का उपयोग करें। मदद के लिए धन्यवाद।
आप होगा बहुत कुछ होना स्पष्ट, नियंत्रण, क्या से ट्रिगर किया? – adeneo
@adeneo मैंने अपना प्रश्न संपादित किया है। धन्यवाद । –