madebymany/sir-trevor-js

Sir Trevor Issues In Angular 2

borntodesign opened this issue · 2 comments

  1. Has anyone got this working yet?
  2. If not I am having a few issues so I think I will just paste my code and someone can tell me what I am doing wrong.

Pages Controller


// Import for forms and validations
import { FormGroup, FormControl, FormBuilder, Validators } from '@angular/forms';

declare var SirTrevor: any; // declared as any, so anything goes

@Component({
  selector: 'app-pages',
  templateUrl: './pages.component.html',
  styleUrls: ['./pages.component.css']
})
export class PagesComponent implements OnInit, OnDestroy {
  editor: any;

  public pageForm: FormGroup; // our model driven form

  constructor() {
    SirTrevor.setDefaults({
      iconUrl: "../assets/sirtrev/sir-trevor-icons.svg"
    });
    SirTrevor.setDefaults({
      uploadUrl: "https://api.cloudinary.com/v1_1/property-roland/image/upload?upload_preset=n3fxornt",
      attachmentName: 'name',
      attachmentFile: 'file',
      attachmentUid: 'uid'
    });
  }

  ngOnInit() {
    // Load initiail blank form group
    this.pageForm = new FormGroup({
    });
    
    if(!this.editor) {
      this.editor = new SirTrevor.Editor({
        el: document.getElementById('sir-editor'),
        defaultType: 'Text',
        iconUrl: '../assets/sirtrev/sir-trevor-icons.svg'
      });
    }
  }
  ngOnDestroy() {
    if(this.editor) {
      this.editor.destroy();
      this.editor = undefined;
    }
  }
  getData() {
    console.log(this.editor.store.retrieve());
    console.log(this.editor.store.toString());
    console.log(this.editor);
  }

}

Pages View

<form [formGroup]="pageForm" (ngSubmit)="getData()" novalidate>
  <textarea id="sir-editor"></textarea>
  <button type="submit" class="btn btn-primary">Data</button>
</form>

The thing is that the data only shows when I click submit twice (weird). Then when I navigate away and come back it does not show any data on save after adding new content.

@borntodesign assume you found a way to get it working, but there's an old comment which would have helped you.

#393 (comment)