{"id":1542,"date":"2024-11-10T17:06:41","date_gmt":"2024-11-10T09:06:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1542\/"},"modified":"2024-11-10T17:06:41","modified_gmt":"2024-11-10T09:06:41","slug":"angularjs%e4%b8%ad%e5%a6%82%e4%bd%95%e4%b8%ba%e5%8a%a8%e6%80%81%e7%94%9f%e6%88%90%e7%9a%84html%e6%b7%bb%e5%8a%a0%e6%8c%87%e4%bb%a4%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1542\/","title":{"rendered":"AngularJS\u4e2d\u5982\u4f55\u4e3a\u52a8\u6001\u751f\u6210\u7684HTML\u6dfb\u52a0\u6307\u4ee4\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173046096447872.jpg\" class=\"aligncenter\" title=\"AngularJS\u4e2d\u5982\u4f55\u4e3a\u52a8\u6001\u751f\u6210\u7684HTML\u6dfb\u52a0\u6307\u4ee4\uff1f\u63d2\u56fe\" alt=\"AngularJS\u4e2d\u5982\u4f55\u4e3a\u52a8\u6001\u751f\u6210\u7684HTML\u6dfb\u52a0\u6307\u4ee4\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 angularjs \u4e2d\u4e3a\u52a8\u6001\u751f\u6210\u7684 html \u6dfb\u52a0\u6307\u4ee4\uff1f<\/strong><\/p>\n<p>\u5f53\u60a8\u52a8\u6001\u751f\u6210 html \u5143\u7d20\u65f6\uff0c\u5982\u4f55\u5c06 angularjs \u6307\u4ee4\u7ed1\u5b9a\u5230\u5b83\u4eec\uff1f\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u60f3\u8981\u6dfb\u52a0\u4e00\u4e2a<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u8981\u5c06\u6307\u4ee4\u7ed1\u5b9a\u5230\u52a8\u6001\u751f\u6210\u7684 html\uff0c\u9700\u8981\u8fdb\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li> <strong>\u7f16\u8bd1 html\uff1a<\/strong>\u4f7f\u7528 $compile \u670d\u52a1\u7f16\u8bd1\u52a8\u6001\u751f\u6210\u7684 html\uff0c\u8be5\u670d\u52a1\u5c06\u89e3\u6790\u6307\u4ee4\u5e76\u521b\u5efa\u4e0e\u5b83\u4eec\u5173\u8054\u7684\u7f16\u8bd1\u51fd\u6570\u3002<\/li>\n<li> <strong>\u6dfb\u52a0\u5230 dom\uff1a<\/strong>\u4f7f\u7528 $compile \u670d\u52a1\u8fd4\u56de\u7684\u7f16\u8bd1\u51fd\u6570\u5c06 html \u6dfb\u52a0\u5230 dom \u4e2d\u3002\u8fd9\u6837 angularjs \u5c31\u80fd\u591f\u8bc6\u522b\u6307\u4ee4\u5e76\u5e94\u7528\u5b83\u4eec\u7684\u529f\u80fd\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0b\u662f\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre>\/\/ \u52a8\u6001\u751f\u6210\u7684 HTML\nconst html = '&lt;a href=\"javascript:void(0);\" ng-click=\"info()\"&gt;\u67e5\u770b&lt;\/a&gt;';\n\n\/\/ \u7f16\u8bd1 HTML\nconst compiledHtml = $compile(html);\n\n\/\/ \u6dfb\u52a0\u5230 DOM\nangular.element(document.body).append(compiledHtml);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u7f16\u8bd1\u540e\u7684 html \u5c06\u88ab\u6dfb\u52a0\u5230 dom \u4e2d\uff0cangularjs \u5c06\u8bc6\u522b ng-click \u6307\u4ee4\u5e76\u5c06\u5176\u7ed1\u5b9a\u5230 info() \u65b9\u6cd5\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fAngularJS\u4e2d\u5982\u4f55\u4e3a\u52a8\u6001\u751f\u6210\u7684HTML\u6dfb\u52a0\u6307\u4ee4\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728 angularjs \u4e2d\u4e3a\u52a8\u6001\u751f\u6210\u7684 html \u6dfb\u52a0\u6307\u4ee4\uff1f \u5f53\u60a8\u52a8\u6001\u751f\u6210 html \u5143\u7d20\u65f6\uff0c\u5982\u4f55\u5c06 angularjs \u6307\u4ee4\u7ed1\u5b9a\u5230\u5b83\u4eec\uff1f\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u60f3\u8981\u6dfb\u52a0\u4e00\u4e2a \u89e3\u51b3\u65b9\u6848\uff1a \u8981\u5c06\u6307\u4ee4\u7ed1\u5b9a\u5230\u52a8\u6001\u751f\u6210\u7684 html\uff0c\u9700\u8981\u8fdb\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u7f16\u8bd1 html\uff1a\u4f7f\u7528 $compile \u670d\u52a1\u7f16\u8bd1\u52a8\u6001\u751f\u6210\u7684 html\uff0c\u8be5\u670d\u52a1\u5c06\u89e3\u6790\u6307\u4ee4\u5e76\u521b\u5efa\u4e0e\u5b83\u4eec\u5173\u8054\u7684\u7f16\u8bd1\u51fd\u6570\u3002 \u6dfb\u52a0\u5230 dom\uff1a\u4f7f\u7528 $compile \u670d\u52a1\u8fd4\u56de\u7684\u7f16\u8bd1\u51fd\u6570\u5c06 html \u6dfb\u52a0\u5230 dom \u4e2d\u3002\u8fd9\u6837 angularjs \u5c31\u80fd\u591f\u8bc6\u522b\u6307\u4ee4\u5e76\u5e94\u7528\u5b83\u4eec\u7684\u529f\u80fd\u3002 \u4ee5\u4e0b\u662f\u793a\u4f8b\u4ee3\u7801\uff1a \/\/ \u52a8\u6001\u751f\u6210\u7684 HTML const html = &#8216;&lt;a href=&#8221;javascript:void(0);&#8221; ng-click=&#8221;info()&#8221;&gt;\u67e5\u770b&lt;\/a&gt;&#8217;; \/\/ \u7f16\u8bd1 HTML const compiledHtml = $compile(html); \/\/ \u6dfb\u52a0\u5230 DOM angular.element(document.body).append(compiledHtml); \u767b\u5f55\u540e\u590d\u5236 \u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u7f16\u8bd1\u540e\u7684 html \u5c06\u88ab\u6dfb\u52a0\u5230 dom [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1542","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=1542"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1542\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}