Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject HTML #35

Closed
robhicks opened this issue Feb 16, 2017 · 4 comments
Closed

Inject HTML #35

robhicks opened this issue Feb 16, 2017 · 4 comments

Comments

@robhicks
Copy link

This is kind of related to 34.

I'm looking for a way to inject safe HTML into an element, like:

angular 1:
angular 2: <div [innerHTML]="theHtmlString">

@davidjamesstone
Copy link
Owner

davidjamesstone commented Feb 16, 2017

There's no support for setting HTML directly in Incremental DOM or superviews.js.
The following could work using currentElement and skip.

<div skip>
  <script>
    const el = currentElement()
    el.innerHTML = data.myHtmlString
  </script>
</div>

This will compile to:

;(function () {
var __target

return function description (data) {
elementOpen("div")
  if (true) {
    skip()
  } else {
    const el = currentElement()
    el.innerHTML = data.myHtmlString
  }
elementClose("div")
}
})()

@robhicks
Copy link
Author

Thanks! I'll give it a try.

@robhicks
Copy link
Author

@davidjamesstone I gave it a try. It compiled as you indicated. I have the data there and the element but calling el.innerHTML = data doesn't do anything.

Any suggestions?

@robhicks
Copy link
Author

Adding skip to the element was the problem. I changed to this and it works:

<div>
    <script>
      if (ctrl.html && ctrl.html !== '') {
        var el = currentElement();
        el.innerHTML = ctrl.html;
      }
      skip();
    </script>
  </div>

I got the idea for doing it this way from google/incremental-dom#283

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants