ERROR TypeError: Cannot read property 'save' of undefined Angular 9

Hi i have a problem, documentEditor component is undefined. I have followed instructions but i can't get it to work...

Here is github link to test project: https://github.com/WingsDevelopment/syncfusion-test

app.component.ts
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  providers: [ToolbarService,EditorServiceSelectionServiceSfdtExportService,TextExportService]
})
export class AppComponent implements OnInit {
  @ViewChild('documentEditorDefault', { static: true }) 
  container: DocumentEditorContainerComponent;
  documentEditor: DocumentEditorComponent;
 
  saveAsDocx() :void {
    // this.container.documentEditor.save('sample','Docx');
    this.documentEditor.save('sample','Docx');
  }
  ngOnInit(): void {
  }
}

1 Reply 1 reply marked as answer

HC Harini Chellappa Syncfusion Team July 13, 2020 12:31 PM UTC

Hi Srdjan, 

Syncfusion Greetings! 

Please update the app.component.html as like below 

<ejs-documenteditorcontainer #documentEditorDefault serviceUrl="https://ej2services.syncfusion.com/production/web-services/api/documenteditor/"  
  [enableToolbar]=true></ejs-documenteditorcontainer> 

Update app.component.ts as like below 

export class AppComponent implements OnInit { 
  @ViewChild('documentEditorDefault', { static: true })  
  public container: DocumentEditorContainerComponent; 

  saveAsDocx() :void { 
    this.container.documentEditor.save('sample','Docx'); 
 
  ngOnInit(): void { 
 


For your reference, please check the below stack blitz sample. 


Regards, 

Harini C 


Marked as answer
Loader.
Up arrow icon