Right here in a JS class, I used “wp.media” to add photographs. I can open the media popup by clicking a button. However getting this error (Uncaught TypeError: Can’t learn properties of undefined (studying ‘state’)) whereas submitting the picture.
constructor ( btn ) {
tremendous();
this.uploaderBtn = $( btn );
this.mediaFrame;
this.occasions();
}
occasions () {
this.uploaderBtn.on( 'click on', this.add.bind( this ) );
}
add ( e ) {
e.preventDefault();
//If the uploader object has already been created, reopen the dialog
if ( this.mediaFrame ) {
this.mediaFrame.open();
return;
}
//Prolong the wp.media object
this.mediaFrame = wp.media.frames.file_frame = wp.media({
title: 'Select Picture',
button: {
textual content: 'Select Picture'
},
a number of: true
});
this.mediaFrame.on('choose', perform() {
const choice = this.mediaFrame.state().get('choice');
console.log( choice );
});
this.mediaFrame.open();
}