{"id":177,"date":"2021-09-03T21:54:36","date_gmt":"2021-09-03T13:54:36","guid":{"rendered":"http:\/\/139.196.75.244\/?p=177"},"modified":"2021-09-09T15:40:15","modified_gmt":"2021-09-09T07:40:15","slug":"nodejs%e5%ad%a6%e4%b9%a0%e4%ba%8c%e3%80%8aangular%e5%ad%a6%e4%b9%a0%e4%b8%89%e3%80%8b%e7%bb%84%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/www.tianjm.cn\/?p=177","title":{"rendered":"\u300aAngular\u5b66\u4e60\u4e09\u300b\u7ec4\u4ef6"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"creating-a-component\">\u521b\u5efa\u4e00\u4e2a\u7ec4\u4ef6<a href=\"https:\/\/angular.cn\/guide\/component-overview#creating-a-component\"><\/a><\/h2>\n\n\n\n<p>Angular CLI \u662f\u7528\u6765\u521b\u5efa\u7ec4\u4ef6\u7684\u6700\u7b80\u9014\u5f84\u3002\u4f60\u4e5f\u53ef\u4ee5\u624b\u52a8\u521b\u5efa\u4e00\u4e2a\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"creating-a-component-using-the-angular-cli\">\u4f7f\u7528 Angular CLI \u521b\u5efa\u7ec4\u4ef6<a href=\"https:\/\/angular.cn\/guide\/component-overview#creating-a-component-using-the-angular-cli\"><\/a><\/h3>\n\n\n\n<p>\u4f7f\u7528 Angular CLI \u521b\u5efa\u4e00\u4e2a\u7ec4\u4ef6\uff1a<\/p>\n\n\n\n<ol><li>\u5728\u7ec8\u7aef\u7a97\u53e3\u4e2d\uff0c\u5bfc\u822a\u5230\u8981\u653e\u7f6e\u4f60\u5e94\u7528\u7684\u76ee\u5f55\u3002<\/li><li>\u8fd0\u884c&nbsp;<code>ng generate component &lt;component-name&gt;<\/code>&nbsp;\u547d\u4ee4\uff0c\u5176\u4e2d&nbsp;<code>&lt;component-name&gt;<\/code>&nbsp;\u662f\u65b0\u7ec4\u4ef6\u7684\u540d\u5b57\u3002<\/li><\/ol>\n\n\n\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u8be5\u547d\u4ee4\u4f1a\u521b\u5efa\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n\n\n\n<ul><li>\u4e00\u4e2a\u4ee5\u8be5\u7ec4\u4ef6\u547d\u540d\u7684\u6587\u4ef6\u5939<\/li><li>\u4e00\u4e2a\u7ec4\u4ef6\u6587\u4ef6&nbsp;<code>&lt;component-name&gt;.component.ts<\/code><\/li><li>\u4e00\u4e2a\u6a21\u677f\u6587\u4ef6&nbsp;<code>&lt;component-name&gt;.component.html<\/code><\/li><li>\u4e00\u4e2a CSS \u6587\u4ef6\uff0c&nbsp;<code>&lt;component-name&gt;.component.css<\/code><\/li><li>\u6d4b\u8bd5\u6587\u4ef6&nbsp;<code>&lt;component-name&gt;.component.spec.ts<\/code><\/li><\/ul>\n\n\n\n<p>\u5176\u4e2d&nbsp;<code>&lt;component-name&gt;<\/code>&nbsp;\u662f\u7ec4\u4ef6\u7684\u540d\u79f0\u3002<\/p>\n\n\n\n<p><em>\u7ec4\u4ef6<\/em>\u63a7\u5236\u5c4f\u5e55\u4e0a\u88ab\u79f0\u4e3a<a href=\"https:\/\/angular.cn\/guide\/glossary#view\"><em>\u89c6\u56fe<\/em><\/a>\u7684\u4e00\u5c0f\u7247\u533a\u57df\u3002<\/p>\n\n\n\n<p>\u4f60\u5728\u7c7b\u4e2d\u5b9a\u4e49\u7ec4\u4ef6\u7684\u5e94\u7528\u903b\u8f91\uff0c\u4e3a\u89c6\u56fe\u63d0\u4f9b\u652f\u6301\u3002 \u7ec4\u4ef6\u901a\u8fc7\u4e00\u4e9b\u7531\u5c5e\u6027\u548c\u65b9\u6cd5\u7ec4\u6210\u7684 API \u4e0e\u89c6\u56fe\u4ea4\u4e92\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export class HeroListComponent implements OnInit {\n  heroes: Hero&#91;] = &#91;];\n  selectedHero: Hero | undefined;\n\n  constructor(private service: HeroService) { }\n\n  ngOnInit() {\n    this.heroes = this.service.getHeroes();\n  }\n\n  selectHero(hero: Hero) { this.selectedHero = hero; }\n}<\/code><\/pre>\n\n\n\n<p>\u5f53\u7528\u6237\u5728\u5e94\u7528\u4e2d\u7a7f\u884c\u65f6\uff0cAngular \u5c31\u4f1a\u521b\u5efa\u3001\u66f4\u65b0\u3001\u9500\u6bc1\u4e00\u4e9b\u7ec4\u4ef6\u3002 \u4f60\u7684\u5e94\u7528\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e9b\u53ef\u9009\u7684<a href=\"https:\/\/angular.cn\/guide\/lifecycle-hooks\">\u751f\u547d\u5468\u671f\u94a9\u5b50<\/a>\uff08\u6bd4\u5982&nbsp;<code>ngOnInit()<\/code>\uff09\u6765\u5728\u6bcf\u4e2a\u7279\u5b9a\u7684\u65f6\u673a\u91c7\u53d6\u884c\u52a8\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>interface OnInit {\n  ngOnInit(): void\n}<\/code><\/pre>\n\n\n\n<p><code>@<a href=\"https:\/\/angular.cn\/api\/core\/Component\">Component<\/a><\/code>&nbsp;\u88c5\u9970\u5668\u4f1a\u6307\u51fa\u7d27\u968f\u5176\u540e\u7684\u90a3\u4e2a\u7c7b\u662f\u4e2a\u7ec4\u4ef6\u7c7b\uff0c\u5e76\u4e3a\u5176\u6307\u5b9a\u5143\u6570\u636e\u3002 \u5728\u4e0b\u9762\u7684\u8303\u4f8b\u4ee3\u7801\u4e2d\uff0c\u4f60\u53ef\u4ee5\u770b\u5230&nbsp;<code>HeroListComponent<\/code>&nbsp;\u53ea\u662f\u4e00\u4e2a\u666e\u901a\u7c7b\uff0c\u5b8c\u5168\u6ca1\u6709 Angular \u7279\u6709\u7684\u6807\u8bb0\u6216\u8bed\u6cd5\u3002 \u76f4\u5230\u7ed9\u5b83\u52a0\u4e0a\u4e86&nbsp;<code>@<a href=\"https:\/\/angular.cn\/api\/core\/Component\">Component<\/a><\/code>&nbsp;\u88c5\u9970\u5668\uff0c\u5b83\u624d\u53d8\u6210\u4e86\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Component({\n  selector:    'app-hero-list',\n  templateUrl: '.\/hero-list.component.html',\n  providers:  &#91; HeroService ]\n})\nexport class HeroListComponent implements OnInit {\n\/* . . . *\/\n}<\/code><\/pre>\n\n\n\n<ul><li><code>selector<\/code>\uff1a\u662f\u4e00\u4e2a CSS \u9009\u62e9\u5668\uff0c\u5b83\u4f1a\u544a\u8bc9 Angular\uff0c\u4e00\u65e6\u5728\u6a21\u677f HTML \u4e2d\u627e\u5230\u4e86\u8fd9\u4e2a\u9009\u62e9\u5668\u5bf9\u5e94\u7684\u6807\u7b7e\uff0c\u5c31\u521b\u5efa\u5e76\u63d2\u5165\u8be5\u7ec4\u4ef6\u7684\u4e00\u4e2a\u5b9e\u4f8b\u3002 \u6bd4\u5982\uff0c\u5982\u679c\u5e94\u7528\u7684 HTML \u4e2d\u5305\u542b&nbsp;<code>&lt;app-hero-list&gt;&lt;\/app-hero-list&gt;<\/code>\uff0cAngular \u5c31\u4f1a\u5728\u8fd9\u4e9b\u6807\u7b7e\u4e2d\u63d2\u5165\u4e00\u4e2a&nbsp;<code>HeroListComponent<\/code>&nbsp;\u5b9e\u4f8b\u7684\u89c6\u56fe\u3002<\/li><li><code>templateUrl<\/code>\uff1a\u8be5\u7ec4\u4ef6\u7684 HTML \u6a21\u677f\u6587\u4ef6\u76f8\u5bf9\u4e8e\u8fd9\u4e2a\u7ec4\u4ef6\u6587\u4ef6\u7684\u5730\u5740\u3002 \u53e6\u5916\uff0c\u4f60\u8fd8\u53ef\u4ee5\u7528&nbsp;<code>template<\/code>&nbsp;\u5c5e\u6027\u7684\u503c\u6765\u63d0\u4f9b\u5185\u8054\u7684 HTML \u6a21\u677f\u3002 \u8fd9\u4e2a\u6a21\u677f\u5b9a\u4e49\u4e86\u8be5\u7ec4\u4ef6\u7684<em>\u5bbf\u4e3b\u89c6\u56fe<\/em>\u3002<\/li><li><code>providers<\/code>\uff1a\u5f53\u524d\u7ec4\u4ef6\u6240\u9700\u7684\u670d\u52a1<a href=\"https:\/\/angular.cn\/guide\/glossary#provider\">\u63d0\u4f9b\u8005<\/a>\u7684\u4e00\u4e2a\u6570\u7ec4\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5b83\u544a\u8bc9 Angular \u8be5\u5982\u4f55\u63d0\u4f9b\u4e00\u4e2a&nbsp;<code>HeroService<\/code>&nbsp;\u5b9e\u4f8b\uff0c\u4ee5\u83b7\u53d6\u8981\u663e\u793a\u7684\u82f1\u96c4\u5217\u8868\u3002<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>\u6a21\u677f\u4e0e\u89c6\u56fe<\/strong><\/p>\n\n\n\n<p>\u4f60\u8981\u901a\u8fc7\u7ec4\u4ef6\u7684\u914d\u5957\u6a21\u677f\u6765\u5b9a\u4e49\u5176\u89c6\u56fe\u3002\u6a21\u677f\u5c31\u662f\u4e00\u79cd HTML\uff0c\u5b83\u4f1a\u544a\u8bc9 Angular \u5982\u4f55\u6e32\u67d3\u8be5\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<p>\u89c6\u56fe\u901a\u5e38\u4f1a\u5206\u5c42\u6b21\u8fdb\u884c\u7ec4\u7ec7\uff0c\u8ba9\u4f60\u80fd\u4ee5 UI \u5206\u533a\u6216\u9875\u9762\u4e3a\u5355\u4f4d\u8fdb\u884c\u4fee\u6539\u3001\u663e\u793a\u6216\u9690\u85cf\u3002 \u4e0e\u7ec4\u4ef6\u76f4\u63a5\u5173\u8054\u7684\u6a21\u677f\u4f1a\u5b9a\u4e49\u8be5\u7ec4\u4ef6\u7684<em>\u5bbf\u4e3b\u89c6\u56fe<\/em>\u3002\u8be5\u7ec4\u4ef6\u8fd8\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a<em>\u5e26\u5c42\u6b21\u7ed3\u6784\u7684\u89c6\u56fe<\/em>\uff0c\u5b83\u5305\u542b\u4e00\u4e9b<em>\u5185\u5d4c\u7684\u89c6\u56fe<\/em>\u4f5c\u4e3a\u5176\u5b83\u7ec4\u4ef6\u7684\u5bbf\u4e3b\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"804\" height=\"313\" src=\"http:\/\/139.196.75.244\/wp-content\/uploads\/2021\/09\/image-1.png\" alt=\"\" class=\"wp-image-181\" srcset=\"https:\/\/www.tianjm.cn\/wp-content\/uploads\/2021\/09\/image-1.png 804w, https:\/\/www.tianjm.cn\/wp-content\/uploads\/2021\/09\/image-1-300x117.png 300w, https:\/\/www.tianjm.cn\/wp-content\/uploads\/2021\/09\/image-1-768x299.png 768w\" sizes=\"(max-width: 804px) 100vw, 804px\" \/><\/figure>\n\n\n\n<p><strong>\u6a21\u677f\u8bed\u6cd5<\/strong><\/p>\n\n\n\n<p>\u6a21\u677f\u5f88\u50cf\u6807\u51c6\u7684 HTML\uff0c\u4f46\u662f\u5b83\u8fd8\u5305\u542b Angular \u7684<a href=\"https:\/\/angular.cn\/guide\/template-syntax\">\u6a21\u677f\u8bed\u6cd5<\/a>\uff0c\u8fd9\u4e9b\u6a21\u677f\u8bed\u6cd5\u53ef\u4ee5\u6839\u636e\u4f60\u7684\u5e94\u7528\u903b\u8f91\u3001\u5e94\u7528\u72b6\u6001\u548c DOM \u6570\u636e\u6765\u4fee\u6539\u8fd9\u4e9b HTML\u3002 \u4f60\u7684\u6a21\u677f\u53ef\u4ee5\u4f7f\u7528<em>\u6570\u636e\u7ed1\u5b9a<\/em>\u6765\u534f\u8c03\u5e94\u7528\u548c DOM \u4e2d\u7684\u6570\u636e\uff0c\u4f7f\u7528<em>\u7ba1\u9053<\/em>\u5728\u663e\u793a\u51fa\u6765\u4e4b\u524d\u5bf9\u5176\u8fdb\u884c\u8f6c\u6362\uff0c\u4f7f\u7528<em>\u6307\u4ee4<\/em>\u6765\u628a\u7a0b\u5e8f\u903b\u8f91\u5e94\u7528\u5230\u8981\u663e\u793a\u7684\u5185\u5bb9\u4e0a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;h2&gt;Hero List&lt;\/h2&gt;\n\n&lt;p&gt;&lt;i&gt;Select a hero from the list to see details.&lt;\/i&gt;&lt;\/p&gt;\n&lt;ul&gt;\n  &lt;li *ngFor=\"let hero of heroes\" (click)=\"selectHero(hero)\"&gt;\n    {{hero.name}}\n  &lt;\/li&gt;\n&lt;\/ul&gt;\n\n&lt;app-hero-detail *ngIf=\"selectedHero\" &#91;hero]=\"selectedHero\"&gt;&lt;\/app-hero-detail&gt;<\/code><\/pre>\n\n\n\n<ul><li><code>*<a href=\"https:\/\/angular.cn\/api\/common\/NgForOf\">ngFor<\/a><\/code>&nbsp;\u6307\u4ee4\u544a\u8bc9 Angular \u5728\u4e00\u4e2a\u5217\u8868\u4e0a\u8fdb\u884c\u8fed\u4ee3\u3002<\/li><li><code>{{hero.name}}<\/code>\u3001<code>(click)<\/code>&nbsp;\u548c&nbsp;<code>[hero]<\/code>&nbsp;\u628a\u7a0b\u5e8f\u6570\u636e\u7ed1\u5b9a\u5230\u53ca\u7ed1\u5b9a\u56de DOM\uff0c\u4ee5\u54cd\u5e94\u7528\u6237\u7684\u8f93\u5165\u3002\u66f4\u591a\u5185\u5bb9\u53c2\u9605\u7a0d\u540e\u7684<a href=\"https:\/\/angular.cn\/guide\/architecture-components#data-binding\">\u6570\u636e\u7ed1\u5b9a<\/a>\u90e8\u5206\u3002<\/li><li>\u6a21\u677f\u4e2d\u7684&nbsp;<code>&lt;app-hero-detail&gt;<\/code>&nbsp;\u6807\u7b7e\u662f\u4e00\u4e2a\u4ee3\u8868\u65b0\u7ec4\u4ef6&nbsp;<code>HeroDetailComponent<\/code>&nbsp;\u7684\u5143\u7d20\u3002&nbsp;<code>HeroDetailComponent<\/code>\uff08\u4ee3\u7801\u7565\uff09\u5b9a\u4e49\u4e86&nbsp;<code>HeroListComponent<\/code>&nbsp;\u7684\u82f1\u96c4\u8be6\u60c5\u5b50\u89c6\u56fe\u3002 \u6ce8\u610f\u89c2\u5bdf\u50cf\u8fd9\u6837\u7684\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u662f\u5982\u4f55\u4e0e\u539f\u751f HTML \u5143\u7d20\u65e0\u7f1d\u7684\u6df7\u5408\u5728\u4e00\u8d77\u7684\u3002<\/li><\/ul>\n\n\n\n<p>\u7406\u89e3\uff0c *ngFor=&#8221;let hero of heroes&#8221;  \u7c7b\u4f3c for \u5faa\u73af foreach(hero in heroes),let \u4e3a\u53d8\u91cf\u4f5c\u7528\u57df\uff0c(click)=&#8221;selectHero(hero)&#8221;\u7c7b\u4f3c onclick = \u201c selectHero(hero) \u201d  \uff0c{{hero.name}} \u4e3a\u8f93\u51fa\u503c\uff0c\u89e3\u6790\u4e0b\u6765\u662f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>foreach(hero in heroes){\n onclick=selecthero(hreo);\n}<\/code><\/pre>\n\n\n\n<p><strong>\u6570\u636e\u7ed1\u5b9a<\/strong><\/p>\n\n\n\n<p>\u5982\u679c\u6ca1\u6709\u6846\u67b6\uff0c\u4f60\u5c31\u8981\u81ea\u5df1\u8d1f\u8d23\u628a\u6570\u636e\u503c\u63a8\u9001\u5230 HTML \u63a7\u4ef6\u4e2d\uff0c\u5e76\u628a\u6765\u81ea\u7528\u6237\u7684\u54cd\u5e94\u8f6c\u6362\u6210\u52a8\u4f5c\u548c\u5bf9\u503c\u7684\u66f4\u65b0\u3002 \u624b\u52a8\u5199\u8fd9\u79cd\u6570\u636e\u63a8\u62c9\u903b\u8f91\u4f1a\u5f88\u67af\u71e5\u3001\u5bb9\u6613\u51fa\u9519\uff0c\u96be\u4ee5\u9605\u8bfb \u2014\u2014 \u6709\u524d\u7aef JavaScript \u5f00\u53d1\u7ecf\u9a8c\u7684\u7a0b\u5e8f\u5458\u4e00\u5b9a\u6df1\u6709\u4f53\u4f1a\u3002<\/p>\n\n\n\n<p>Angular \u652f\u6301<em>\u53cc\u5411\u6570\u636e\u7ed1\u5b9a<\/em>\uff0c\u8fd9\u662f\u4e00\u79cd\u5bf9\u6a21\u677f\u4e2d\u7684\u5404\u4e2a\u90e8\u4ef6\u4e0e\u7ec4\u4ef6\u4e2d\u7684\u5404\u4e2a\u90e8\u4ef6\u8fdb\u884c\u534f\u8c03\u7684\u673a\u5236\u3002 \u5f80\u6a21\u677f HTML \u4e2d\u6dfb\u52a0\u7ed1\u5b9a\u6807\u8bb0\u53ef\u4ee5\u544a\u8bc9 Angular \u8be5\u5982\u4f55\u8fde\u63a5\u5b83\u4eec\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"800\" height=\"286\" src=\"http:\/\/139.196.75.244\/wp-content\/uploads\/2021\/09\/image-2.png\" alt=\"\" class=\"wp-image-183\" srcset=\"https:\/\/www.tianjm.cn\/wp-content\/uploads\/2021\/09\/image-2.png 800w, https:\/\/www.tianjm.cn\/wp-content\/uploads\/2021\/09\/image-2-300x107.png 300w, https:\/\/www.tianjm.cn\/wp-content\/uploads\/2021\/09\/image-2-768x275.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p>\u7528\u4f8b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;li&gt;{{hero.name}}&lt;\/li&gt;\n&lt;app-hero-detail &#91;hero]=\"selectedHero\"&gt;&lt;\/app-hero-detail&gt;\n&lt;li (click)=\"selectHero(hero)\"&gt;&lt;\/li&gt;\n&lt;input type=\"text\" id=\"hero-name\" &#91;(ngModel)]=\"hero.name\"&gt;<\/code><\/pre>\n\n\n\n<p>\u5728\u53cc\u5411\u7ed1\u5b9a\u4e2d\uff0c\u6570\u636e\u5c5e\u6027\u503c\u901a\u8fc7\u5c5e\u6027\u7ed1\u5b9a\u4ece\u7ec4\u4ef6\u6d41\u5230\u8f93\u5165\u6846\u3002\u7528\u6237\u7684\u4fee\u6539\u901a\u8fc7\u4e8b\u4ef6\u7ed1\u5b9a\u6d41\u56de\u7ec4\u4ef6\uff0c\u628a\u5c5e\u6027\u503c\u8bbe\u7f6e\u4e3a\u6700\u65b0\u7684\u503c\u3002<\/p>\n\n\n\n<p><strong>\u7ba1\u9053<\/strong><\/p>\n\n\n\n<p>Angular \u7684\u7ba1\u9053\u53ef\u4ee5\u8ba9\u4f60\u5728\u6a21\u677f\u4e2d\u58f0\u660e\u663e\u793a\u503c\u7684\u8f6c\u6362\u903b\u8f91\u3002 \u5e26\u6709&nbsp;<code>@<a href=\"https:\/\/angular.cn\/api\/core\/Pipe\">Pipe<\/a><\/code>&nbsp;\u88c5\u9970\u5668\u7684\u7c7b\u4e2d\u4f1a\u5b9a\u4e49\u4e00\u4e2a\u8f6c\u6362\u51fd\u6570\uff0c\u7528\u6765\u628a\u8f93\u5165\u503c\u8f6c\u6362\u6210\u4f9b\u89c6\u56fe\u663e\u793a\u7528\u7684\u8f93\u51fa\u503c\u3002<\/p>\n\n\n\n<p>Angular \u81ea\u5e26\u4e86\u5f88\u591a\u7ba1\u9053\uff0c\u6bd4\u5982&nbsp;<a href=\"https:\/\/angular.cn\/api\/common\/DatePipe\">date<\/a>&nbsp;\u7ba1\u9053\u548c&nbsp;<a href=\"https:\/\/angular.cn\/api\/common\/CurrencyPipe\">currency<\/a>&nbsp;\u7ba1\u9053\uff0c\u5b8c\u6574\u7684\u5217\u8868\u53c2\u9605&nbsp;<a href=\"https:\/\/angular.cn\/api?type=pipe\">Pipes API \u5217\u8868<\/a>\u3002\u4f60\u4e5f\u53ef\u4ee5\u81ea\u5df1\u5b9a\u4e49\u4e00\u4e9b\u65b0\u7ba1\u9053\u3002<\/p>\n\n\n\n<p>\u8981\u5728 HTML \u6a21\u677f\u4e2d\u6307\u5b9a\u503c\u7684\u8f6c\u6362\u65b9\u5f0f\uff0c\u8bf7\u4f7f\u7528&nbsp;<a href=\"https:\/\/angular.cn\/guide\/pipes\">\u7ba1\u9053\u64cd\u4f5c\u7b26 (|)<\/a>\u3002<\/p>\n\n\n\n<p><code>{{interpolated_value | pipe_name}}<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;p&gt;Today is {{'2020\/01\/30' | date}}&lt;\/p&gt;\n&lt;p&gt;Today is {{'2020\/01\/30' | date:'fullDate'}}&lt;\/p&gt;\n&lt;p&gt;The time is {{'2020\/01\/30' | date:'shortTime'}}&lt;\/p&gt;<\/code><\/pre>\n\n\n\n<p>\u7ed3\u679c<\/p>\n\n\n\n<p>Today is Jan 30, 2020<\/p>\n\n\n\n<p>Today is Thursday, January 30, 2020<\/p>\n\n\n\n<p>The time is 12:00 AM<\/p>\n\n\n\n<p><strong>\u6307\u4ee4<\/strong><\/p>\n\n\n\n<p>Angular \u7684\u6a21\u677f\u662f<em>\u52a8\u6001\u7684<\/em>\u3002\u5f53 Angular \u6e32\u67d3\u5b83\u4eec\u7684\u65f6\u5019\uff0c\u4f1a\u6839\u636e<em>\u6307\u4ee4<\/em>\u7ed9\u51fa\u7684\u6307\u793a\u5bf9 DOM \u8fdb\u884c\u8f6c\u6362\u3002 \u6307\u4ee4\u5c31\u662f\u4e00\u4e2a\u5e26\u6709&nbsp;<code>@<a href=\"https:\/\/angular.cn\/api\/core\/Directive\">Directive<\/a>()<\/code>&nbsp;\u88c5\u9970\u5668\u7684\u7c7b\u3002<\/p>\n\n\n\n<p>\u7ec4\u4ef6\u4ece\u6280\u672f\u89d2\u5ea6\u4e0a\u8bf4\u5c31\u662f\u4e00\u4e2a\u6307\u4ee4\uff0c\u4f46\u662f\u7531\u4e8e\u7ec4\u4ef6\u5bf9 Angular \u5e94\u7528\u6765\u8bf4\u975e\u5e38\u72ec\u7279\u3001\u975e\u5e38\u91cd\u8981\uff0c\u56e0\u6b64 Angular \u4e13\u95e8\u5b9a\u4e49\u4e86&nbsp;<code>@<a href=\"https:\/\/angular.cn\/api\/core\/Component\">Component<\/a>()<\/code>&nbsp;\u88c5\u9970\u5668\uff0c\u5b83\u4f7f\u7528\u4e00\u4e9b\u9762\u5411\u6a21\u677f\u7684\u7279\u6027\u6269\u5c55\u4e86&nbsp;<code>@<a href=\"https:\/\/angular.cn\/api\/core\/Directive\">Directive<\/a>()<\/code>&nbsp;\u88c5\u9970\u5668\u3002<\/p>\n\n\n\n<p><em>\u7ed3\u6784\u578b\u6307\u4ee4<\/em>\u548c<em>\u5c5e\u6027\u578b\u6307\u4ee4<\/em><\/p>\n\n\n\n<p><strong>\u7ed3\u6784\u578b\u6307\u4ee4<\/strong><\/p>\n\n\n\n<p>\u901a\u8fc7\u6dfb\u52a0\u3001\u79fb\u9664\u6216\u66ff\u6362 DOM \u5143\u7d20\u6765\u4fee\u6539\u5e03\u5c40\u3002 \u8fd9\u4e2a\u8303\u4f8b\u6a21\u677f\u4f7f\u7528\u4e86\u4e24\u4e2a\u5185\u7f6e\u7684\u7ed3\u6784\u578b\u6307\u4ee4\u6765\u4e3a\u8981\u6e32\u67d3\u7684\u89c6\u56fe\u6dfb\u52a0\u7a0b\u5e8f\u903b\u8f91\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;li *ngFor=\"let a of &#91;1,2,3]\"&gt;{{a}}&lt;\/li&gt;\n&lt;app-hero-detail *ngIf=\"selectedHero\"&gt;&lt;\/app-hero-detail&gt;\/\/\u6682\u65f6\u6ca1\u5f04\u660e\u767d<\/code><\/pre>\n\n\n\n<p>\u7ed3\u679c<\/p>\n\n\n\n<p>1<\/p>\n\n\n\n<p>2<\/p>\n\n\n\n<p>3<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u521b\u5efa\u4e00\u4e2a\u7ec4\u4ef6 Angular CLI \u662f\u7528\u6765\u521b\u5efa\u7ec4\u4ef6\u7684\u6700\u7b80\u9014\u5f84\u3002\u4f60\u4e5f&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12],"tags":[],"_links":{"self":[{"href":"https:\/\/www.tianjm.cn\/index.php?rest_route=\/wp\/v2\/posts\/177"}],"collection":[{"href":"https:\/\/www.tianjm.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tianjm.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tianjm.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tianjm.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=177"}],"version-history":[{"count":22,"href":"https:\/\/www.tianjm.cn\/index.php?rest_route=\/wp\/v2\/posts\/177\/revisions"}],"predecessor-version":[{"id":212,"href":"https:\/\/www.tianjm.cn\/index.php?rest_route=\/wp\/v2\/posts\/177\/revisions\/212"}],"wp:attachment":[{"href":"https:\/\/www.tianjm.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tianjm.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tianjm.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}