{"id":1528,"date":"2024-11-10T12:08:30","date_gmt":"2024-11-10T04:08:30","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1528\/"},"modified":"2024-11-10T12:08:30","modified_gmt":"2024-11-10T04:08:30","slug":"angularjs-%e4%b8%ad%e5%a6%82%e4%bd%95%e5%8a%a8%e6%80%81%e6%b7%bb%e5%8a%a0-html-%e5%b9%b6%e7%bb%91%e5%ae%9a%e6%8c%87%e4%bb%a4%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1528\/","title":{"rendered":"AngularJS \u4e2d\u5982\u4f55\u52a8\u6001\u6dfb\u52a0 HTML \u5e76\u7ed1\u5b9a\u6307\u4ee4\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173045737391567.jpg\" class=\"aligncenter\" title=\"AngularJS \u4e2d\u5982\u4f55\u52a8\u6001\u6dfb\u52a0 HTML \u5e76\u7ed1\u5b9a\u6307\u4ee4\uff1f\u63d2\u56fe\" alt=\"AngularJS \u4e2d\u5982\u4f55\u52a8\u6001\u6dfb\u52a0 HTML \u5e76\u7ed1\u5b9a\u6307\u4ee4\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>angularjs \u4e2d\u52a8\u6001\u6dfb\u52a0 html \u5e76\u7ed1\u5b9a\u6307\u4ee4<\/strong><\/p>\n<p>\u5728 angularjs \u4e2d\uff0c\u52a8\u6001\u6dfb\u52a0 html \u5e76\u4e3a\u5176\u7ed1\u5b9a\u6307\u4ee4\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u4efb\u52a1\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u80fd\u5e0c\u671b\u5728\u54cd\u5e94\u7279\u5b9a\u4e8b\u4ef6\u65f6\u6dfb\u52a0\u4e00\u7ec4\u5143\u7d20\u3002<\/p>\n<p>\u8981\u52a8\u6001\u6dfb\u52a0 html \u5e76\u7ed1\u5b9a\u6307\u4ee4\uff0c\u8bf7\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li> <strong>\u7f16\u8bd1 html<\/strong>\uff1a\u4f7f\u7528 $compile \u670d\u52a1\u6765\u7f16\u8bd1 html \u4ee3\u7801\u6bb5\u3002\u6b64\u670d\u52a1\u5c06\u89e3\u6790 html \u5e76\u521b\u5efa\u4e0e angularjs \u5e94\u7528\u7a0b\u5e8f\u5173\u8054\u7684\u5143\u7d20\u3002<\/li>\n<li> <strong>\u94fe\u63a5\u5143\u7d20<\/strong>\uff1a\u7f16\u8bd1\u540e\uff0c\u9700\u8981\u5c06\u5143\u7d20\u94fe\u63a5\u5230 angularjs \u3002\u4e3a\u6b64\uff0c\u4f7f\u7528 $compile \u8fd4\u56de\u7684\u94fe\u63a5\u51fd\u6570\u3002<\/li>\n<li> <strong>\u5c06\u5143\u7d20\u6dfb\u52a0\u5230 dom<\/strong>\uff1a\u6700\u540e\uff0c\u5c06\u751f\u6210\u7684\u5143\u7d20\u6dfb\u52a0\u5230 dom \u4e2d\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 appendchild() \u6216\u5176\u4ed6 dom \u64cd\u4f5c\u65b9\u6cd5\u6765\u5b9e\u73b0\u6b64\u76ee\u7684\u3002<\/li>\n<\/ol>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u793a\u4f8b\u6f14\u793a\u4e86\u5982\u4f55\u5728 angularjs \u5e94\u7528\u7a0b\u5e8f\u4e2d\u6267\u884c\u6b64\u8fc7\u7a0b\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>const app = angular.module('myApp', []);\n\napp.controller('MyCtrl', function($scope, $compile) {\n  $scope.addElement = function() {\n    \/\/ \u7f16\u8bd1 HTML\n    const html = '&lt;a href=\"javascript:void(0);\" ng-click=\"info()\"&gt;\u67e5\u770b&lt;\/a&gt;';\n    const compiledElement = $compile(html)($scope);\n\n    \/\/ \u6dfb\u52a0\u5230 DOM\n    const target = document.getElementById('target');\n    target.appendChild(compiledElement[0]);\n  };\n});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0caddelement \u51fd\u6570\u52a8\u6001\u6dfb\u52a0<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fAngularJS \u4e2d\u5982\u4f55\u52a8\u6001\u6dfb\u52a0 HTML \u5e76\u7ed1\u5b9a\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>angularjs \u4e2d\u52a8\u6001\u6dfb\u52a0 html \u5e76\u7ed1\u5b9a\u6307\u4ee4 \u5728 angularjs \u4e2d\uff0c\u52a8\u6001\u6dfb\u52a0 html \u5e76\u4e3a\u5176\u7ed1\u5b9a\u6307\u4ee4\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u4efb\u52a1\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u80fd\u5e0c\u671b\u5728\u54cd\u5e94\u7279\u5b9a\u4e8b\u4ef6\u65f6\u6dfb\u52a0\u4e00\u7ec4\u5143\u7d20\u3002 \u8981\u52a8\u6001\u6dfb\u52a0 html \u5e76\u7ed1\u5b9a\u6307\u4ee4\uff0c\u8bf7\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u7f16\u8bd1 html\uff1a\u4f7f\u7528 $compile \u670d\u52a1\u6765\u7f16\u8bd1 html \u4ee3\u7801\u6bb5\u3002\u6b64\u670d\u52a1\u5c06\u89e3\u6790 html \u5e76\u521b\u5efa\u4e0e angularjs \u5e94\u7528\u7a0b\u5e8f\u5173\u8054\u7684\u5143\u7d20\u3002 \u94fe\u63a5\u5143\u7d20\uff1a\u7f16\u8bd1\u540e\uff0c\u9700\u8981\u5c06\u5143\u7d20\u94fe\u63a5\u5230 angularjs \u3002\u4e3a\u6b64\uff0c\u4f7f\u7528 $compile \u8fd4\u56de\u7684\u94fe\u63a5\u51fd\u6570\u3002 \u5c06\u5143\u7d20\u6dfb\u52a0\u5230 dom\uff1a\u6700\u540e\uff0c\u5c06\u751f\u6210\u7684\u5143\u7d20\u6dfb\u52a0\u5230 dom \u4e2d\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 appendchild() \u6216\u5176\u4ed6 dom \u64cd\u4f5c\u65b9\u6cd5\u6765\u5b9e\u73b0\u6b64\u76ee\u7684\u3002 \u4ee5\u4e0b\u4ee3\u7801\u793a\u4f8b\u6f14\u793a\u4e86\u5982\u4f55\u5728 angularjs \u5e94\u7528\u7a0b\u5e8f\u4e2d\u6267\u884c\u6b64\u8fc7\u7a0b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b const app = angular.module(&#8216;myApp&#8217;, []); app.controller(&#8216;MyCtrl&#8217;, function($scope, $compile) { $scope.addElement = function() { \/\/ \u7f16\u8bd1 HTML [&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-1528","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1528","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=1528"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1528\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}