KGBRS Ответов: 0

Встраивание формы jot в angular4


Hi,
I want to embed Jot form(jsform) in the Angular4 application. I tried with some simple HTML it is working fine. and I have implemented in an Angular application but it was throwing an error as 
"Cannot read property 'attachEvent' of null
    at FrameBuilder.addEvent"


Что я уже пробовал:

I'm trying in the following way.

test.component.html
<span [innerHTML]="url|testhtmlstring"></span>

test.component.ts
this.url = '<script src="https://form.jotform.me/jsform/myform-some-sample-url"></script>';

Pipe
import { Pipe } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';

@Pipe({
  name: 'testhtmlstring',
  pure: true
})

export class JsSanitization {

  constructor(private domSanitizer: DomSanitizer) { }

  handleExternalScriptsInHtmlString(string) {
    let that = this;
    var parser = new DOMParser();
    var scripts = parser.parseFromString(string, 'text/html').getElementsByTagName('script');
    var results = [];

    for (var i = 0; i < scripts.length; i++) {
      var src = scripts[i].getAttribute('src');
      if (src.length && results.indexOf(src) === -1) {
        results.push(src);
        that.addScript(src);
      }
    }
    return results;
  }

  addScript(src) {
    var script = document.createElement('script');
    script.setAttribute('src', src);
    document.body.appendChild(script);
  }


  transform(htmlContent: any) {
    let sanitizeHtmlContent = this.domSanitizer.bypassSecurityTrustHtml(htmlContent);
    this.handleExternalScriptsInHtmlString(htmlContent);
    return sanitizeHtmlContent;
  }
}

but it is showing the error as "Cannot read property 'attachEvent' of null
    at FrameBuilder.addEvent"


It is working fine when I'm trying to working with sample HTML.
<html>
<head>
<script type='text/javascript' src="https://form.jotform.me/jsform/myform-some-sample-url"></script>
</head>
<body>
<h2>Hello World</h2>
</body>
</html>

0 Ответов