search

Home  >  Q&A  >  body text

angular.js - How to parse the html generated in the instruction

return {
            restrict: 'EA',
            link: function (scope, element, attr) {
                element.bind('mouseenter', function() {
                    this.after("<p style='position: absolute;'><img src=" + this.src + " /></p>")
                });
            }
        }

For example, as shown above, using jquery’s after method, this p is displayed as a string on the page. How can it be parsed directly?

世界只因有你世界只因有你2795 days ago816

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-05-15 17:14:05

    Use $compile

    Written a small online demo

    http://embed.plnkr.co/egEOkZv...

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-15 17:14:05

    This is caused by the quotation marks in the title of the question

    this.after("<p style='position: absolute;'><img src=" + this.src + " /></p>")
    

    Obviously the url here is missing a quotation mark. The src of img should be wrapped in quotation marks. You can add single quotation marks on both sides

    this.after("<p style='position: absolute;'><img src='" + this.src + "' /></p>")
    

    Your string on the page is also src without quotes

    reply
    0
  • Cancelreply