{"id":1440,"date":"2024-11-10T16:30:01","date_gmt":"2024-11-10T08:30:01","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1440\/"},"modified":"2024-11-10T16:30:01","modified_gmt":"2024-11-10T08:30:01","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-angularjs-%e4%b8%ad%e5%8a%a8%e6%80%81%e6%b7%bb%e5%8a%a0%e5%b8%a6%e6%9c%89%e6%8c%87%e4%bb%a4%e7%9a%84-html-%e5%85%83%e7%b4%a0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1440\/","title":{"rendered":"\u5982\u4f55\u5728 AngularJS \u4e2d\u52a8\u6001\u6dfb\u52a0\u5e26\u6709\u6307\u4ee4\u7684 HTML \u5143\u7d20\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173043505779300.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728 AngularJS \u4e2d\u52a8\u6001\u6dfb\u52a0\u5e26\u6709\u6307\u4ee4\u7684 HTML \u5143\u7d20\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728 AngularJS \u4e2d\u52a8\u6001\u6dfb\u52a0\u5e26\u6709\u6307\u4ee4\u7684 HTML \u5143\u7d20\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u52a8\u6001\u6dfb\u52a0\u5e26\u6307\u4ee4\u7684 html<\/strong><\/p>\n<p>\u5982\u4f55\u52a8\u6001\u751f\u6210\u5e76\u5411 dom \u4e2d\u6dfb\u52a0\u5305\u542b angularjs \u6307\u4ee4\u7684 html \u5143\u7d20\uff1f<\/p>\n<p>\u8981\u52a8\u6001\u6dfb\u52a0\u5e26\u6709\u6307\u4ee4\u7684 html\uff0c\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528 ng-compile \u6307\u4ee4\u7f16\u8bd1 html<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>ng-compile \u6307\u4ee4\u5c06\u4e00\u6bb5 html \u5b57\u7b26\u4e32\u7f16\u8bd1\u6210 angularjs \u6a21\u677f\u51fd\u6570\u3002\u8fd9\u4f7f angularjs \u80fd\u591f\u89e3\u6790\u6307\u4ee4\u5e76\u5c06\u5b83\u4eec\u4e0e\u8fde\u63a5\u3002<\/p>\n<pre>var newhtml = '&lt;a href=\"javascript:void(0);\" ng-click=\"info()\"&gt;\u67e5\u770b&lt;\/a&gt;';\nvar compiledhtml = $compile(newhtml)($scope);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u5c06\u7f16\u8bd1\u540e\u7684 html \u6dfb\u52a0\u5230 dom<\/strong><\/p>\n<p>\u4f7f\u7528 jquery \u6216\u539f\u751f javascript \u5c06\u7f16\u8bd1\u540e\u7684 html\u6dfb\u52a0\u5230 dom \u4e2d\u3002<\/p>\n<pre>$('#parent-element').append(compiledhtml);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u8c03\u7528 $apply<\/strong><\/p>\n<p>\u7f16\u8bd1\u540e\u7684 html \u5df2\u6dfb\u52a0\u5230 dom \u4e2d\uff0c\u4f46 angularjs \u5c1a\u672a\u5bf9\u5176\u8fdb\u884c\u68c0\u6d4b\u3002\u9700\u8981\u8c03\u7528 $apply \u65b9\u6cd5\u6765\u544a\u77e5 angularjs \u5bf9\u66f4\u6539\u8fdb\u884c\u68c0\u67e5\u3002<\/p>\n<pre>$scope.$apply();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ol>\n<p>\u5b8c\u6210\u8fd9\u4e9b\u6b65\u9aa4\u540e\uff0c\u52a8\u6001\u751f\u6210\u7684 html \u5143\u7d20\u5c06\u5305\u542b angularjs \u6307\u4ee4\uff0c\u5e76\u4e14\u53ef\u4ee5\u8bbf\u95ee\u4f5c\u7528\u57df\u4e2d\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728 AngularJS \u4e2d\u52a8\u6001\u6dfb\u52a0\u5e26\u6709\u6307\u4ee4\u7684 HTML \u5143\u7d20\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>\u52a8\u6001\u6dfb\u52a0\u5e26\u6307\u4ee4\u7684 html \u5982\u4f55\u52a8\u6001\u751f\u6210\u5e76\u5411 dom \u4e2d\u6dfb\u52a0\u5305\u542b angularjs \u6307\u4ee4\u7684 html \u5143\u7d20\uff1f \u8981\u52a8\u6001\u6dfb\u52a0\u5e26\u6709\u6307\u4ee4\u7684 html\uff0c\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u4f7f\u7528 ng-compile \u6307\u4ee4\u7f16\u8bd1 html \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b ng-compile \u6307\u4ee4\u5c06\u4e00\u6bb5 html \u5b57\u7b26\u4e32\u7f16\u8bd1\u6210 angularjs \u6a21\u677f\u51fd\u6570\u3002\u8fd9\u4f7f angularjs \u80fd\u591f\u89e3\u6790\u6307\u4ee4\u5e76\u5c06\u5b83\u4eec\u4e0e\u8fde\u63a5\u3002 var newhtml = &#8216;&lt;a href=&#8221;javascript:void(0);&#8221; ng-click=&#8221;info()&#8221;&gt;\u67e5\u770b&lt;\/a&gt;&#8217;; var compiledhtml = $compile(newhtml)($scope); \u767b\u5f55\u540e\u590d\u5236 \u5c06\u7f16\u8bd1\u540e\u7684 html \u6dfb\u52a0\u5230 dom \u4f7f\u7528 jquery \u6216\u539f\u751f javascript \u5c06\u7f16\u8bd1\u540e\u7684 html\u6dfb\u52a0\u5230 dom \u4e2d\u3002 $(&#8216;#parent-element&#8217;).append(compiledhtml); \u767b\u5f55\u540e\u590d\u5236 \u8c03\u7528 $apply \u7f16\u8bd1\u540e\u7684 html \u5df2\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-1440","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1440","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=1440"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1440\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}