{"id":38970,"date":"2023-06-05T13:08:59","date_gmt":"2023-08-07T14:14:29","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%b8%bareact%e7%94%a8%e6%88%b7%e6%8f%90%e4%be%9b%e7%9a%84angular2%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97\/"},"modified":"2024-04-30T07:25:11","modified_gmt":"2024-04-29T23:25:11","slug":"%e4%b8%bareact%e7%94%a8%e6%88%b7%e6%8f%90%e4%be%9b%e7%9a%84angular2%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%b8%bareact%e7%94%a8%e6%88%b7%e6%8f%90%e4%be%9b%e7%9a%84angular2%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97\/","title":{"rendered":"\u4e3aReact\u7528\u6237\u63d0\u4f9b\u7684Angular2\u5165\u95e8\u6307\u5357"},"content":{"rendered":"<p>\u5bf9\u4e8e\u4f7f\u7528\u8fc7React\u7684\u4eba\u6765\u8bf4\uff0c\u6211\u5c06\u603b\u7ed3React\u4e2d\u7684\u67d0\u4e9b\u6982\u5ff5\u5728Angular 2\u4e2d\u7684\u5bf9\u5e94\u5173\u7cfb\u662f\u600e\u6837\u7684\u3002\u4f5c\u4e3a\u4e00\u4e2a\u4e4b\u524d\u4f7f\u7528React\u7684\u7528\u6237\uff0c\u5f53\u6211\u5f00\u59cb\u5b66\u4e60Angular 2\u65f6\uff0c\u6211\u5e0c\u671b\u80fd\u6709\u8fd9\u6837\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u987a\u4fbf\u8bf4\u4e00\u53e5\uff0c\u56e0\u4e3a\u8981\u79f0\u5176\u4e3aAngular\u800c\u4e0d\u662fAngular2\u3002\u6240\u4ee5\u4e0b\u6587\u4e2d\u63d0\u5230\u7684Angular\u6307\u7684\u662fAngular 2.x\u3002<\/p>\n<h1>\u5e94\u7528\u7a0b\u5e8f\u7684\u542f\u52a8<\/h1>\n<p>\u56de\u5e94<\/p>\n<pre class=\"post-pre\"><code><span class=\"cp\">&lt;!doctype html&gt;<\/span>\r\n<span class=\"nt\">&lt;html<\/span> <span class=\"na\">lang=<\/span><span class=\"s\">\"en\"<\/span><span class=\"nt\">&gt;<\/span>\r\n  <span class=\"nt\">&lt;head&gt;<\/span>\r\n    <span class=\"nt\">&lt;title&gt;<\/span>React App<span class=\"nt\">&lt;\/title&gt;<\/span>\r\n  <span class=\"nt\">&lt;\/head&gt;<\/span>\r\n  <span class=\"nt\">&lt;body&gt;<\/span>\r\n    <span class=\"nt\">&lt;div<\/span> <span class=\"na\">id=<\/span><span class=\"s\">\"root\"<\/span><span class=\"nt\">&gt;&lt;\/div&gt;<\/span>\r\n  <span class=\"nt\">&lt;\/body&gt;<\/span>\r\n<span class=\"nt\">&lt;\/html&gt;<\/span>\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>import React from 'react';\r\nimport ReactDOM from 'react-dom';\r\n\r\nclass App extends Component {\r\n  render() {\r\n    return (\r\n      &lt;div&gt;\r\n        &lt;p&gt;hello world&lt;\/p&gt;\r\n      &lt;\/div&gt;\r\n    );\r\n  }\r\n}\r\n\r\nReactDOM.render(\r\n  &lt;App \/&gt;,\r\n  document.getElementById('root')\r\n);\r\n<\/code><\/pre>\n<p>\u5728React\u4e2d\uff0c\u4f7f\u7528ReactDOM.render\u6765\u6307\u5b9a\u5e94\u7528\u7a0b\u5e8f\u7684\u6839\u7ec4\u4ef6\u548c\u76ee\u6807DOM\u5143\u7d20\u3002<\/p>\n<p>\u89d2\u5ea6<\/p>\n<pre class=\"post-pre\"><code><span class=\"cp\">&lt;!doctype html&gt;<\/span>\r\n<span class=\"nt\">&lt;html&gt;<\/span>\r\n<span class=\"nt\">&lt;head&gt;<\/span>\r\n  <span class=\"nt\">&lt;title&gt;<\/span>Angular2<span class=\"nt\">&lt;\/title&gt;<\/span>\r\n<span class=\"nt\">&lt;\/head&gt;<\/span>\r\n<span class=\"nt\">&lt;body&gt;<\/span>\r\n  <span class=\"nt\">&lt;app-root&gt;<\/span>Loading...<span class=\"nt\">&lt;\/app-root&gt;<\/span>\r\n<span class=\"nt\">&lt;\/body&gt;<\/span>\r\n<span class=\"nt\">&lt;\/html&gt;<\/span>\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>import { platformBrowserDynamic } from '@angular\/platform-browser-dynamic';\r\nimport { AppModule } from '.\/app.module';\r\n\r\nplatformBrowserDynamic().bootstrapModule(AppModule);\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>import { BrowserModule } from '@angular\/platform-browser';\r\nimport { NgModule } from '@angular\/core';\r\n\r\nimport { AppComponent } from '.\/app.component';\r\n\r\n@NgModule({\r\n  declarations: [\r\n    AppComponent\r\n  ],\r\n  imports: [\r\n    BrowserModule\r\n  ],\r\n  providers: [],\r\n  bootstrap: [AppComponent]\r\n})\r\nexport class AppModule { }\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>import { Component } from '@angular\/core';\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  template: `\r\n    &lt;div&gt;\r\n      &lt;p&gt;{{title}}&lt;\/p&gt;\r\n    &lt;\/div&gt;\r\n  `\r\n})\r\nexport class AppComponent {\r\n  title = 'hello world';\r\n}\r\n<\/code><\/pre>\n<p>\u5728Angular\u4e2d\uff0c\u9700\u8981\u4f5c\u4e3a\u542f\u52a8\u70b9\u7684\u662fModule\u3002Module\u662f\u5e94\u7528\u7a0b\u5e8f\u529f\u80fd\u7684\u5355\u5143\uff0c\u5305\u62ecComponent\uff0cService\u7b49\u3002\u5728@NgModule\u88c5\u9970\u5668\u7684bootstrap\u4e2d\u6307\u5b9a\u7684Component\u5c06\u4f1a\u88ab\u663e\u793a\u3002<\/p>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u901a\u8fc7platformBrowserDynamic().bootstrapModule(AppModule);\u542f\u52a8\u4e86AppModule\uff0c\u7531\u4e8ebootstrap: [AppComponent]\uff0c\u6240\u4ee5AppComponent\u88ab\u6e32\u67d3\u51fa\u6765\uff0c\u7531\u4e8eselector: &#8216;app-root&#8217;\uff0cLoading&#8230; \u4f1a\u88ab\u66ff\u6362\u4e3a<\/p>\n<div>\n<p>hello world<\/p>\n<\/div>\n<p>\u3002<\/p>\n<h1>\u6210\u5206<\/h1>\n<p>\u56de\u5e94<\/p>\n<pre class=\"post-pre\"><code>class App extends React.Component {\r\n  constructor(props) {\r\n    super(props);\r\n\r\n    this.state = {\r\n      todos: [\r\n        'sleep',\r\n        'do nothing'\r\n      ]\r\n    };\r\n  }\r\n\r\n  componentDidMount() {\r\n    console.log('mounted :)');\r\n  }\r\n\r\n  render() {\r\n    return (\r\n      &lt;div className=\"App\"&gt;\r\n        &lt;h1&gt;{this.props.title}&lt;\/h1&gt;\r\n        &lt;ul&gt;\r\n          {this.state.todos.map((todo, i) =&gt; &lt;li key={i}&gt;&lt;p&gt;{todo}&lt;\/p&gt;&lt;\/li&gt;)}\r\n        &lt;\/ul&gt;\r\n        &lt;button type=\"button\" onClick={this.props.onClick}&gt; +1 :)&lt;\/button&gt;\r\n        { this.props.children }\r\n      &lt;\/div&gt;\r\n    );\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>\u5982\u679c\u5728\u7ee7\u627f React.Component \u7684\u7c7b\u4e2d\u5b9e\u73b0\u4e86 render \u65b9\u6cd5\uff0c\u90a3\u5c31\u662f\u4e00\u4e2a React \u7684\u7ec4\u4ef6\uff01\u53e6\u5916\uff0ccomponentDidMount \u7b49\u751f\u547d\u5468\u671f\u65b9\u6cd5\u3001props\u3001props.children\u3001state \u8fd9\u4e9b\u90fd\u662f\u4ee3\u8868\u6027\u7684 React \u7ec4\u4ef6\u529f\u80fd\u5427\u3002<\/p>\n<p>\u89d2\u5ea6<\/p>\n<p>\u6b63\u5982\u4e4b\u524d\u7684\u4f8b\u5b50\u6240\u793a\uff0cAngular\u4e2d\u7684HTML\u4ee3\u7801\u4e0d\u518d\u5199\u5728React\u7684render\u65b9\u6cd5\u4e2d\uff0c\u800c\u662f\u5199\u5728@Component\u88c5\u9970\u5668\u4e2d\u3002\u901a\u8fc7\u8bbe\u7f6etemplateUrl: &#8216;app.component.html&#8217;\uff0c\u8fd8\u53ef\u4ee5\u5c06HTML\u6587\u4ef6\u4e0e\u4ee3\u7801\u5206\u79bb\u3002CSS\u4e5f\u662f\u7c7b\u4f3c\u7684\u3002<br \/>\n\u5728React\u4e2d\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u7c7b\u540d\u6765\u5f15\u7528\u7ec4\u4ef6\uff0c\u5982\uff0c\u4f46\u5728Angular\u4e2d\uff0c\u9009\u62e9\u5668\u4e2d\u6307\u5b9a\u7684\u5b57\u7b26\u4e32\u5c06\u66ff\u6362\u8be5\u7ec4\u4ef6\u3002<br \/>\n\u7531\u4e8eAngular\u4e5f\u6709\u7c7b\u4f3c\u4e8eReact\u7684props\u3001props.children\u3001state\u548c\u751f\u547d\u5468\u671f\u65b9\u6cd5\u7b49\u529f\u80fd\uff0c\u8ba9\u6211\u4eec\u4e00\u4e00\u6765\u770b\u4e00\u4e0b\u3002<\/p>\n<h1>\u9053\u5177<\/h1>\n<pre class=\"post-pre\"><code>import { Component } from '@angular\/core';\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  template: `\r\n    &lt;sample-child [title]=\"'hello'\" (onHello)=\"handleHello($event)\"&gt;&lt;\/sample-child&gt;\r\n  `\r\n})\r\nexport class AppComponent {\r\n  handleHello(ev: any) {\r\n    console.log(ev);\r\n  }\r\n}\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>import { Component, Input, Output, EventEmitter } from '@angular\/core';\r\n\r\n@Component({\r\n  selector: 'sample-child',\r\n  template: `\r\n    &lt;h1&gt;{{title}}&lt;\/h1&gt;\r\n    &lt;button type=\"button\" (click)=\"clicked()\"&gt;say hello&lt;\/button&gt;\r\n  `\r\n})\r\nexport class SampleChildComponent {\r\n  @Input() title: string;\r\n  @Output() onHello = new EventEmitter&lt;any&gt;();\r\n\r\n  clicked() {\r\n    this.onHello.emit({ 'i said': 'hello' });\r\n  }\r\n}\r\n<\/code><\/pre>\n<h2>\u6bcd\u7d44\u4ef6\u2192\u5b50\u7d44\u4ef6<\/h2>\n<p>\u8981\u5c06\u6570\u636e\u4ece\u7236\u7ec4\u4ef6\u4f20\u9012\u7ed9\u5b50\u7ec4\u4ef6\uff0c\u9700\u8981\u5728\u5b50\u7ec4\u4ef6\u4e0a\u5b9a\u4e49\u4e00\u4e2a\u5e26\u6709 @Input \u6ce8\u89e3\u7684\u5c5e\u6027\u3002\u7236\u7ec4\u4ef6\u901a\u8fc7\u4f7f\u7528 [title]=&#8221;&#8216;hello'&#8221; \u7684\u5f62\u5f0f\u6765\u6307\u5b9a\u8981\u4f20\u9012\u7684\u5c5e\u6027\uff0c\u4f8b\u5982 \u3002\u8fd9\u5c31\u662f\u5c5e\u6027\u7ed1\u5b9a\u7684\u65b9\u5f0f\u3002<\/p>\n<blockquote><p>\u6211\u77e5\u9053\u4f60\u53ef\u80fd\u4f1a\u5bf9 \u4e2d\u7684 &#8220;&#8216;hello'&#8221; \u8868\u793a\u6cd5\u611f\u5230\u56f0\u60d1\uff0c\u4f46\u5b9e\u9645\u4e0a\u8fd9\u662f React \u4e2d\u7684 \u7684\u5199\u6cd5\u3002\u5728 React \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 {} \u6765\u7f16\u5199 JavaScript \u8868\u8fbe\u5f0f\uff0c\u800c\u5728 Angular \u7684\u7ed1\u5b9a\u4e2d\uff0c\u53cc\u5f15\u53f7\u4e2d\u7684\u5185\u5bb9\u5c31\u4f1a\u88ab\u5f53\u4f5c JavaScript \u5904\u7406\u3002\u6240\u4ee5\u5f53\u6211\u4eec\u60f3\u4f20\u9012\u4e00\u4e2a\u666e\u901a\u7684\u5b57\u7b26\u4e32\u65f6\uff0c\u5c31\u9700\u8981\u5199\u6210 &#8220;&#8216;hello'&#8221;\u3002<\/p><\/blockquote>\n<h2>\u5b50\u7ec4\u4ef6\u2192\u7236\u7ec4\u4ef6<\/h2>\n<p>\u4e3a\u4e86\u5c06\u4e8b\u4ef6\u4ece\u5b50\u7ec4\u4ef6\u4f20\u9012\u7ed9\u7236\u7ec4\u4ef6\uff0c\u5728\u5b50\u7ec4\u4ef6\u4e2d\u5b9a\u4e49\u4e00\u4e2a\u5177\u6709@Output()\u6ce8\u91ca\u7684EventEmitter\u5c5e\u6027\uff0c\u4f8b\u5982\u5b50\u7ec4\u4ef6\u4e2d\u7684@Output() onHello = new EventEmitter(); \u7136\u540e\u5728\u7236\u7ec4\u4ef6\u4e2d\u4f7f\u7528\u7684\u65b9\u5f0f\uff0c\u901a\u8fc7\u7528()\u62ec\u8d77\u6765\u6307\u5b9a\u3002 handleHello\u662f\u7236\u7ec4\u4ef6\u7c7b\u4e2d\u7684\u65b9\u6cd5\u3002 $event\u662f\u4e00\u4e2a\u7279\u6b8a\u7684\u7b26\u53f7\uff0c\u5b83\u5305\u542b\u4e8b\u4ef6\u7684\u6d88\u606f\u6216\u8d1f\u8f7d\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5b83\u5305\u542b\u4e00\u4e2a\u540d\u4e3a{ &#8216;i said&#8217;: &#8216;hello&#8217; }\u7684JSON\u5bf9\u8c61\u3002\u8fd9\u5c31\u662f\u4e8b\u4ef6\u7ed1\u5b9a\u3002<br \/>\n\u9664\u6b64\u4e4b\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u5e38\u7528\u4e8e\u8868\u5355\u7b49\u7684Two-way\u6570\u636e\u7ed1\u5b9a\uff0c\u4f8b\u5982<input type=\"text\" \/>\u3002\u7531\u4e8e\u5305\u542b\u4e86\u7236\u7ec4\u4ef6\u5230\u5b50\u7ec4\u4ef6\u548c\u5b50\u7ec4\u4ef6\u5230\u7236\u7ec4\u4ef6\u7684\u53cc\u5411\u7ed1\u5b9a\uff0c[(ngModel)]\u8868\u793a\u8fd9\u4e2a\u610f\u601d\u3002\u5982\u679c\u4e0d\u719f\u6089\u7684\u8bdd\u53ef\u80fd\u4f1a\u611f\u5230\u6709\u4e9b\u56f0\u60d1\u3002<\/p>\n<h1>\u7ec4\u4ef6\u7684\u5b50\u5143\u7d20<\/h1>\n<pre class=\"post-pre\"><code>import { Component } from '@angular\/core';\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  template: `\r\n    &lt;my-frame&gt;\r\n      &lt;p&gt;in my frame :)&lt;\/p&gt;\r\n    &lt;\/my-frame&gt;\r\n  `\r\n})\r\nexport class AppComponent {\r\n}\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>import { Component } from '@angular\/core';\r\n\r\n@Component({\r\n  selector: 'my-frame',\r\n  template: `\r\n    &lt;div class=\"myframe\"&gt;\r\n      &lt;ng-content&gt;&lt;\/ng-content&gt;\r\n    &lt;\/div&gt;\r\n  `,\r\n  styles: [`\r\n    .myframe {\r\n      color: red;\r\n    }\r\n  `]\r\n})\r\nexport class MyFrameComponent {\r\n}\r\n<\/code><\/pre>\n<p>\u8981\u8f93\u51fa\u5728\u81ea\u5df1\u7684\u6807\u7b7e\u5185\u5b9a\u4e49\u7684HTML\uff0c\u53ef\u4ee5\u4f7f\u7528\u3002\u4e0a\u8ff0\u793a\u4f8b\u7684\u8f93\u51fa\u662f\u4ec0\u4e48\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"nt\">&lt;div<\/span> <span class=\"na\">class=<\/span><span class=\"s\">\"myframe\"<\/span><span class=\"nt\">&gt;<\/span>\r\n  <span class=\"nt\">&lt;p&gt;<\/span>in my frame :)<span class=\"nt\">&lt;\/p&gt;<\/span>\r\n<span class=\"nt\">&lt;\/div&gt;<\/span>\r\n<\/code><\/pre>\n<p>\u5728\u65c1\u8fb9\uff0c.myframe\u7684CSS\u751f\u6548\uff0c\u6587\u5b57\u4f1a\u53d8\u6210\u7ea2\u8272\u3002<\/p>\n<h2>\u9648\u8ff0<\/h2>\n<p>\u5728Angular\u4e2d\uff0c\u53ef\u4ee5\u5c06\u7c7b\u5185\u7684\u5b9e\u4f8b\u8fdb\u884c\u5355\u5411\u6216\u53cc\u5411\u7ed1\u5b9a\u3002\u6ca1\u6709\u4ec0\u4e48\u7279\u522b\u8981\u8bf4\u7684\u3002<\/p>\n<h2>\u751f\u547d\u5468\u671f\u65b9\u6cd5<\/h2>\n<pre class=\"post-pre\"><code>import { Component, OnInit, OnDestroy } from '@angular\/core';\r\nimport { Subscription } from 'rxjs';\r\nimport { SampleService } from '.\/sample.service';\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  template: `\r\n    &lt;p&gt;{{message}}&lt;p&gt;\r\n    &lt;button (click)=\"fetchMessage()\"&gt;fetch&lt;\/button&gt;\r\n  `,\r\n  providers: [\r\n    SampleService\r\n  ]\r\n})\r\nexport class LifeCycleSampleComponent implements OnInit, OnDestroy {\r\n\r\n  message: string = 'initial message';\r\n  subscription: Subscription;\r\n\r\n  constructor(private sampleService: SampleService) { }\r\n\r\n  fetchMessage() {\r\n    this.sampleService.nextMessage();\r\n  }\r\n\r\n  ngOnInit() {\r\n    this.subscription = this.sampleService.message.subscribe(message =&gt; this.message = message);\r\n  }\r\n\r\n  ngOnDestroy() {\r\n    this.subscription.unsubscribe();\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>\u5728Angular\u4e2d\u4e5f\u6709\u7c7b\u4f3c\u4e8eReact\u7684componentDidMount\u548ccomponentWillUnmount\u7b49\u751f\u547d\u5468\u671f\u65b9\u6cd5\u3002\u8981\u5b9e\u73b0\u5b83\u4eec\uff0c\u53ef\u4ee5\u901a\u8fc7\u5c06\u76f8\u5e94\u7684\u751f\u547d\u5468\u671f\u6df7\u5165\u5230class MyComponent extends OnInit\u4e2d\uff0c\u5e76\u5728ngOnInit\u7b49\u65b9\u6cd5\u4e2d\u7f16\u5199\u5b9e\u73b0\u3002\u5f53\u7c7b\u770b\u5230\u8981\u5b9e\u73b0\u7684\u751f\u547d\u5468\u671f\u65b9\u6cd5\u65f6\uff0c\u660e\u786e\u8d77\u89c1\u4f1a\u5f88\u597d\uff01<br \/>\n\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u8ba2\u9605\u4e86Service\u7c7b\uff08\u7a0d\u540e\u4f1a\u63d0\u5230\uff09\u5728Component\u521d\u59cb\u5316\u65f6\u6301\u6709\u7684Observable\uff0c\u5e76\u5728Component\u88ab\u9500\u6bc1\u65f6\u53d6\u6d88\u4e86\u8ba2\u9605\u3002\u6211\u8ba4\u4e3a\u6ce8\u518c\u548c\u53d6\u6d88\u4e8b\u4ef6\u76d1\u542c\u5668\u662f\u6700\u5148\u60f3\u5230\u7684\u7528\u4f8b\u3002<\/p>\n<h2>\u5728React\u4e2d\u6ca1\u6709\u7684\u670d\u52a1<\/h2>\n<pre class=\"post-pre\"><code>import { Injectable } from '@angular\/core';\r\nimport { Observable, Subject } from 'rxjs';\r\n\r\n@Injectable()\r\nexport class SampleService {\r\n\r\n  private _message: Subject&lt;string&gt;;\r\n  message: Observable&lt;string&gt;;\r\n\r\n  constructor() {\r\n    this._message = new Subject&lt;string&gt;();\r\n    this.message = this._message.asObservable();\r\n  }\r\n\r\n  nextMessage() {\r\n    this._message.next('next message');\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>\u5728\u5904\u7406\u4ec5\u5305\u542b\u89c6\u56fe\u7684React\u65f6\uff0c\u6ca1\u6709\u5730\u65b9\u7f16\u5199\u4e1a\u52a1\u903b\u8f91\u548c\u526f\u4f5c\u7528\u7b49\u3002\u56e0\u6b64\uff0c\u6211\u8ba4\u4e3a\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u8bb8\u591a\u4eba\u9009\u62e9\u5f15\u5165Flux\u67b6\u6784\u3002\u5728Angular\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u4f5c\u4e3a\u670d\u52a1\uff08Service\uff09\u6765\u5904\u7406\u8fd9\u4e9b\u4e1c\u897f\uff0c\u5e76\u53ef\u4ee5\u4ece\u7ec4\u4ef6\u4e2d\u4f7f\u7528\u5b83\u3002\u901a\u8fc7\u5728\u670d\u52a1\u4e2d\u5b58\u50a8\u6570\u636e\uff0c\u5e76\u63d0\u4f9b\u83b7\u53d6\u548c\u4fee\u6539\u6570\u636e\u7684\u65b9\u6cd5\uff0c\u6216\u8005\u901a\u8fc7\u89e6\u53d1\u4e8b\u4ef6\u6216\u53ef\u89c2\u5bdf\u5bf9\u8c61\u6765\u5b9e\u73b0\u6570\u636e\u66f4\u6539\u7684\u901a\u77e5\u673a\u5236\u3002<\/p>\n<p>\u670d\u52a1\u7684\u5b9e\u4f8b\u5316\u4e0d\u9700\u8981\u624b\u52a8\u521b\u5efa\uff0c\u800c\u662f\u901a\u8fc7Angular\u7684DI\uff08\u4f9d\u8d56\u6ce8\u5165\uff09\u673a\u5236\u6765\u5b8c\u6210\u3002\u6211\u4eec\u7ed9\u670d\u52a1\u6dfb\u52a0@Injectable\u6ce8\u89e3\uff0c\u5e76\u5728\u4f7f\u7528\u8be5\u670d\u52a1\u7684\u7ec4\u4ef6\u6216\u6a21\u5757\u4e2d\u63d0\u4f9b\u8005\uff08providers\uff09\u5c5e\u6027\u4e2d\u52a0\u5165\u8be5\u670d\u52a1\u3002\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5728\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570\u4e0a\u58f0\u660e\u670d\u52a1\u6765\u83b7\u5f97\u8be5\u670d\u52a1\u7684\u5b9e\u4f8b\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6bcf\u6b21\u5728providers\u4e2d\u6dfb\u52a0\u670d\u52a1\u65f6\uff0c\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u670d\u52a1\u5b9e\u4f8b\u3002\u56e0\u6b64\uff0c\u5982\u679c\u8981\u4f7f\u670d\u52a1\u5728\u6574\u4e2a\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5171\u4eab\u6570\u636e\uff0c\u6211\u4eec\u9700\u8981\u5c06\u5176\u5199\u5728\u5e94\u7528\u7a0b\u5e8f\u7684\u6a21\u5757providers\u4e2d\uff0c\u800c\u4e0d\u662f\u7ec4\u4ef6\u4e2d\u3002<\/p>\n<h1>\u8def\u7531\u5668 (l\u00f9 q\u00ec)<\/h1>\n<p>\u56de\u5e94<\/p>\n<pre class=\"post-pre\"><code>\/\/ github.com\/ReactTraining\/react-router\/README.md \u304b\u3089\r\nrender((\r\n  &lt;Router history={browserHistory}&gt;\r\n    &lt;Route path=\"\/\" component={App}&gt;\r\n      &lt;Route path=\"about\" component={About}\/&gt;\r\n      &lt;Route path=\"users\" component={Users}&gt;\r\n        &lt;Route path=\"\/user\/:userId\" component={User}\/&gt;\r\n      &lt;\/Route&gt;\r\n      &lt;Route path=\"*\" component={NoMatch}\/&gt;\r\n    &lt;\/Route&gt;\r\n  &lt;\/Router&gt;\r\n), document.getElementById('root'))\r\n<\/code><\/pre>\n<p>\u7531\u4e8eReact\u672c\u8eab\u6ca1\u6709\u8def\u7531\u529f\u80fd\uff0c\u6240\u4ee5\u6211\u8ba4\u4e3a\u4f1a\u4f7f\u7528\u50cfreact-router\u8fd9\u6837\u7684\u5e93\u3002\u4f7f\u7528\u65b9\u6cd5\u5f88\u7b80\u5355\uff0c\u53ea\u9700\u5217\u4e3e\u8def\u5f84\uff08path\uff09\u548c\u7ec4\u4ef6\uff08component\uff09\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"gi\">+ import { RouterModule } from '@angular\/router';\r\n+ import { routes } from '.\/app.routes';\r\n<\/span>\r\n\r\n<span class=\"err\">@NgModule({<\/span>\r\n  ...\r\n  imports: [\r\n    HttpModule,\r\n<span class=\"gi\">+   RouterModule.forRoot(routes)\r\n<\/span>  ],\r\n  providers: [],\r\n  bootstrap: [AppComponent]\r\n<span class=\"err\">})<\/span>\r\nexport class AppModule { }\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code><span class=\"k\">import<\/span> <span class=\"p\">{<\/span> <span class=\"nx\">Routes<\/span> <span class=\"p\">}<\/span> <span class=\"k\">from<\/span> <span class=\"dl\">'<\/span><span class=\"s1\">@angular\/router<\/span><span class=\"dl\">'<\/span><span class=\"p\">;<\/span>\r\n\r\n<span class=\"k\">import<\/span> <span class=\"p\">{<\/span> <span class=\"nx\">TodosComponent<\/span> <span class=\"p\">}<\/span> <span class=\"k\">from<\/span> <span class=\"dl\">'<\/span><span class=\"s1\">.\/todos\/todos.component<\/span><span class=\"dl\">'<\/span><span class=\"p\">;<\/span>\r\n<span class=\"k\">import<\/span> <span class=\"p\">{<\/span> <span class=\"nx\">UsersComponent<\/span> <span class=\"p\">}<\/span> <span class=\"k\">from<\/span> <span class=\"dl\">'<\/span><span class=\"s1\">.\/users\/users.component<\/span><span class=\"dl\">'<\/span><span class=\"p\">;<\/span>\r\n\r\n<span class=\"k\">export<\/span> <span class=\"kd\">const<\/span> <span class=\"nx\">routes<\/span><span class=\"p\">:<\/span> <span class=\"nx\">Routes<\/span> <span class=\"o\">=<\/span> <span class=\"p\">[<\/span>\r\n  <span class=\"p\">{<\/span> <span class=\"na\">path<\/span><span class=\"p\">:<\/span> <span class=\"dl\">'<\/span><span class=\"s1\">todos<\/span><span class=\"dl\">'<\/span><span class=\"p\">,<\/span> <span class=\"na\">component<\/span><span class=\"p\">:<\/span> <span class=\"nx\">TodosComponent<\/span> <span class=\"p\">},<\/span>\r\n  <span class=\"p\">{<\/span> <span class=\"na\">path<\/span><span class=\"p\">:<\/span> <span class=\"dl\">'<\/span><span class=\"s1\">users<\/span><span class=\"dl\">'<\/span><span class=\"p\">,<\/span> <span class=\"na\">component<\/span><span class=\"p\">:<\/span> <span class=\"nx\">UsersComponent<\/span> <span class=\"p\">}<\/span>\r\n<span class=\"p\">];<\/span>\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>import { Component } from '@angular\/core';\r\n@Component({\r\n  selector: 'my-app',\r\n  template: `\r\n     &lt;h1&gt;{{title}}&lt;\/h1&gt;\r\n     &lt;a routerLink=\"\/todos\"&gt;Todos&lt;\/a&gt;\r\n     &lt;a routerLink=\"\/users\"&gt;Users&lt;\/a&gt;\r\n     &lt;router-outlet&gt;&lt;\/router-outlet&gt;\r\n   `\r\n})\r\nexport class AppComponent {\r\n  title = 'root component';\r\n}\r\n<\/code><\/pre>\n<p>Angular\u5177\u6709\u8def\u7531\u529f\u80fd\uff0c\u53ef\u4ee5\u4f7f\u7528 @angular\/router \u5bfc\u5165\u6a21\u5757\u6765\u4f7f\u7528\u3002\u8def\u7531\u7684\u5b9a\u4e49\u4e0ereact-router\u7c7b\u4f3c\uff0c\u901a\u8fc7\u8def\u5f84\u6765\u7f16\u5199\u7ec4\u4ef6\u3002\u5339\u914d\u8def\u7531\u7684\u7ec4\u4ef6\u5c06\u5728 \u4e2d\u6e32\u67d3\u3002<\/p>\n<p>\u572812\u67089\u65e5\u5728\u4e1c\u4eac\u4e3e\u884c\u7684Angular\u805a\u4f1a\u4e0a\uff0c\u51fa\u73b0\u4e86angular\/core\u7248\u672c2.x\u4e0eangular\/router\u7248\u672c3.x\u4e0d\u5339\u914d\u7684\u95ee\u9898\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4e0b\u4e00\u4e2aAngular\u7684\u4e3b\u8981\u7248\u672c\u5c06\u4e0d\u662f3\uff0c\u800c\u662f4\u3002<\/p>\n<h1>\u521b\u5efa\u4e00\u4e2aReact\u5e94\u7528<\/h1>\n<p>\u5728\u4e2d\u6587\u4e2d\uff0c\u7c7b\u4f3c\u4e8ecreate-react-app\u7684\u5de5\u5177\u662fangular-cli\u3002\u5b83\u53ef\u4ee5\u751f\u6210\u4e00\u4e2a\u8bbe\u7f6e\u4e86Typescript\u3001Webpack\u3001karma\u7b49\u7b49\u7684Angular\u5e94\u7528\u7684\u6a21\u677f\u3002\u5b83\u4e0d\u4ec5\u53ef\u4ee5\u751f\u6210Component\u548cService\u7684\u6a21\u677f\u4ee5\u53ca\u76f8\u5e94\u7684\u6d4b\u8bd5\u4ee3\u7801\uff0c\u8fd8\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5bfc\u5165\u5230NgModule\u4e2d\uff0c\u63d0\u4f9b\u4e86\u4fbf\u5229\u7684\u529f\u80fd\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"nv\">$ <\/span>npm i <span class=\"nt\">-g<\/span> angular-cli <span class=\"c\"># ng \u30b3\u30de\u30f3\u30c9\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308b<\/span>\r\n<span class=\"nv\">$ <\/span>ng new my-angular-app <span class=\"c\"># Angular\u30a2\u30d7\u30ea\u3092\u751f\u6210\u3059\u308b<\/span>\r\n<span class=\"nv\">$ <\/span><span class=\"nb\">cd <\/span>my-angular-app\r\n<span class=\"nv\">$ <\/span>ng serve <span class=\"c\"># webpack-dev-server\u3092\u8d77\u52d5<\/span>\r\n<span class=\"nv\">$ <\/span>ng <span class=\"nb\">test<\/span>\r\n<span class=\"nv\">$ <\/span>ng e2e\r\n<span class=\"nv\">$ <\/span>ng build\r\n<span class=\"nv\">$ <\/span>ng g component my-component <span class=\"c\"># generate\u3092\u7701\u7565\u3057\u3066g<\/span>\r\ninstalling component\r\n  create src\/app\/my-component\/my-component.component.css\r\n  create src\/app\/my-component\/my-component.component.html\r\n  create src\/app\/my-component\/my-component.component.spec.ts\r\n  create src\/app\/my-component\/my-component.component.ts\r\n<span class=\"nv\">$ <\/span>ng g service my-service\r\ninstalling service\r\n  create src\/app\/my-service.service.spec.ts\r\n  create src\/app\/my-service.service.ts\r\n  WARNING Service is generated but not provided, it must be provided to be used\r\n<\/code><\/pre>\n<p>\u56e0\u4e3a\u4e2a\u4eba\u5bf9\u4e8e\u50cfWebpack\u8fd9\u6837\u7684\u8bbe\u7f6e\u8f83\u4e3a\u56f0\u96be\uff0c\u6240\u4ee5\u80fd\u591f\u901a\u8fc7\u8fd9\u79cd\u5de5\u5177\u6765\u8fdb\u884c\u8865\u5145\u662f\u975e\u5e38\u611f\u6fc0\u7684\u3002<\/p>\n<h1>\u4f7f\u7528React Native<\/h1>\n<p>\u5728\u5bf9React Native\u8fdb\u884c\u56de\u5e94\u7684\u4f4d\u7f6e\u4e0a\uff0c\u6709\u4e00\u4e9b\u5e93\uff0c\u6bd4\u5982ionic2\u3001OnsenUI\u548cNativeScript\u3002\u636e\u8bf4\u8fd8\u6709\u4e00\u4e2a\u540d\u4e3aangular\/react-native-renderer\u7684\u5e93\uff0c\u5b83\u5c06React Native\u7684\u6e32\u67d3\u5668\u4e0eAngular\u8fde\u63a5\u8d77\u6765\u3002<\/p>\n<p>\u5728\u8fd9\u4e9b\u4e2d\uff0c\u6211\u7a0d\u5fae\u63a5\u89e6\u4e86\u4e00\u4e0bionic2\uff0c\u6211\u53d1\u73b0ionic2\u63d0\u4f9b\u7684\u7ec4\u4ef6\u53ef\u4ee5\u5728Web\/iOS\/Android\u4e0a\u8fd0\u884c\uff0c\u8fd9\u79cd\u4e00\u6b21\u7f16\u5199\uff0c\u5230\u5904\u8fd0\u884c\u7684\u7279\u6027\u8ba9\u6211\u611f\u5230\u9707\u64bc\u3002\u771f\u662f\u725b\u903c\u554a\uff01<\/p>\n<pre class=\"post-pre\"><code>\/\/ \u3069\u306e\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u3067\u3082\u52d5\u304f\r\n&lt;ion-list&gt;\r\n  &lt;button ion-item *ngFor=\"let item of items\" (click)=\"itemSelected(item)\"&gt;\r\n    &lt;my-item&gt;{{ item }}&lt;\/my-item&gt;\r\n  &lt;\/button&gt;  \r\n&lt;\/ion-list&gt;\r\n<\/code><\/pre>\n<h1>\u5916\u4f20<\/h1>\n<p>\u6d88\u9664\u5bf9Angular\u7684\u4e0d\u9002\u611f<\/p>\n<h2>\u6211\u4e0d\u559c\u6b22\u65e0\u9650\u5730\u8bb0\u4f4fng-xxx\u3002<\/h2>\n<p>\u6211\u4e2a\u4eba\u7684\u8bb0\u5fc6\u662f\u5f53\u6211\u7a0d\u5fae\u7528\u8fc7Angular 1.x\u65f6\uff0c\u65e0\u8bba\u505a\u4ec0\u4e48\u90fd\u5fc5\u987b\u4f7f\u7528ng-xxx\uff0c\u5982\u679c\u6709\u9519\u8bef\u5c31\u8981\u67e5\u627eng-xxx\u4ee5\u53ca\u51fa\u73b0\u4e86\u4ec0\u4e48\u9519\u8bef\u4fe1\u606f\u5e76\u53bb\u8c37\u6b4c\u641c\u7d22&#8230;\u611f\u89c9\u5f88\u8f9b\u82e6\u3002\u4f46\u5728Angular 2\u4e2d\uff0c\u8fd9\u4e9b\u95ee\u9898\u597d\u50cf\u6709\u6240\u51cf\u8f7b\u3002\u73b0\u5728\u53ea\u6709ng-for\u548cng-if\u8fd9\u4e9b\u89d2\u8272\u51fa\u73b0\uff0c\u5e76\u4e14\u9519\u8bef\u4fe1\u606f\u4e5f\u53d8\u5f97\u66f4\u597d\uff0c\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\u53ea\u8981\u8bfb\u61c2\u5199\u7684\u5185\u5bb9\u5c31\u80fd\u4fee\u590d\u3002<\/p>\n<h2>\u6709\u4eba\u8bf4JSX\u5f88\u7cdf\u7cd5\uff0c\u56e0\u4e3a\u5b83\u53ea\u662f\u9644\u5728\u7c7b\u4e0a\u7684\u4e00\u4e2a\u5de8\u5927\u7684\u88c5\u9970\u5668\uff0c\u5e76\u4e14\u6a21\u677f\u53ea\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5b57\u7b26\u4e32\uff0c\u8fd9\u66f4\u7cdf\u7cd5\uff08\u7701\u7565\uff09<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u79cd\u53ef\u80fd\u7684\u6c49\u8bed\u8868\u8fbe\u65b9\u5f0f\uff1a<br \/>\n\u867d\u7136\u6a21\u677f\u53ea\u662f\u4e00\u4e2a\u666e\u901a\u7684\u5b57\u7b26\u4e32\uff0c\u4f46\u5728\u50cfWebStorm\u6216\u5b89\u88c5\u4e86\u6269\u5c55\u7684VSCode\u7b49\u7f16\u8f91\u5668\u4e2d\uff0c\u5b83\u4eec\u63d0\u4f9b\u4e86\u8bed\u6cd5\u9ad8\u4eae\u529f\u80fd\uff0c\u4ece\u800c\u5927\u5927\u51cf\u5c11\u4e86\u56f0\u6270\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d37f937434c4406c74982\/63-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2016-12-14 23.36.01.png\" \/><\/div>\n<p>\u5f53\u7136\u4e5f\u53ef\u4ee5\u5c06\u6a21\u677f\u4e0e\u7ec4\u4ef6\u5206\u5f00\uff0c\u901a\u8fc7templateUrl: &#8216;foo.component.html&#8217;\u7684\u65b9\u5f0f\u8fdb\u884c\u5f15\u7528\u3002\u7531\u4e8e\u6a21\u677f\u53ea\u662f\u666e\u901a\u7684\u5b57\u7b26\u4e32\uff0c\u6240\u4ee5\u5728\u6267\u884c\u4e4b\u524d\u65e0\u6cd5\u77e5\u9053\u6a21\u677f\u4e2d\u662f\u5426\u5b58\u5728\u9519\u8bef\u7684\u95ee\u9898\u3002\u56e0\u6b64\uff0c\u6700\u597d\u7f16\u5199\u7ec4\u4ef6\u662f\u5426\u88ab\u6e32\u67d3\u7684\u6700\u57fa\u672c\u6d4b\u8bd5\uff0c\u6216\u8005\u8fdb\u884cAoT\u7f16\u8bd1\u4ee5\u5728\u6267\u884c\u4e4b\u524d\u53d1\u73b0\u9519\u8bef\u3002\uff08\u5b9e\u9645\u4e0a\uff0c\u6709\u4eba\u63d0\u5230AoT\u662f\u5fc5\u9700\u7684\uff09<\/p>\n<h1>\u603b\u7ed3<\/h1>\n<p>\u6211\u5927\u81f4\u4ecb\u7ecd\u4e86React\u89d2\u5ea6\u7684\u57fa\u672c\u8981\u7d20\u3002Angular\u672c\u4f53\u5df2\u7ecf\u7a33\u5b9a\u4e86\uff0c\u4f46\u662f\u751f\u6001\u7cfb\u7edf\u8fd8\u6ca1\u6709\u50cfReact\u90a3\u6837\u6210\u719f\uff0c\u6240\u4ee5\u76ee\u524d\u7684\u95ee\u9898\u662f\u4f9d\u8d56\u9879\u4e2d\u6709\u5f88\u591abeta\u7248\u672c\uff0c\u4f46\u662f\u8fd9\u662f\u4e00\u4e2a\u80fd\u591f\u6109\u5feb\u5730\u7f16\u5199Web\u5e94\u7528\u7a0b\u5e8f\u7684\u6846\u67b6\uff0c\u6240\u4ee5\u5982\u679c\u60a8\u8fd8\u6ca1\u6709\u63a5\u89e6\u8fc7\uff0c\u8bf7\u52a1\u5fc5\u8bd5\u8bd5\uff01<\/p>\n<h1>\u8bf7\u5f15\u7528<\/h1>\n<p>\u5728\u5b66\u4e60Angular\u5165\u95e8\u8fc7\u7a0b\u4e2d\uff0c\u6211\u89c9\u5f97\u5229\u7528Google\u7ffb\u8bd1\u4e00\u624b\u8fdb\u884c\u9605\u8bfb\u5b98\u65b9\u6587\u6863\u662f\u6700\u4f73\u9009\u62e9\u3002\u4f60\u53ef\u4ee5\u6309\u7167\u300a\u82f1\u96c4\u4e4b\u65c5\u300b\u6559\u7a0b\u9010\u6b65\u5b66\u4e60\uff0c\u901a\u8fc7Plunker\u8fd9\u4e2a\u80fd\u591f\u5728\u6d4f\u89c8\u5668\u4e0a\u8fd0\u884cJS\u5e94\u7528\u7a0b\u5e8f\u7684\u7f51\u7ad9\uff0c\u6bcf\u4e2a\u6b65\u9aa4\u90fd\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u4f9b\u4f60\u7b80\u5355\u6d4b\u8bd5\uff0c\u5e76\u4e14\u4f60\u4e5f\u53ef\u4ee5\u4e0b\u8f7d\u6587\u4ef6\u538b\u7f29\u5305\uff0c\u5728\u672c\u5730\u4f7f\u7528\u4f60\u5e38\u7528\u7684\u7f16\u8f91\u5668\u8fdb\u884c\u4fee\u6539\u3002\u5728\u4e0b\u8f7d\u7684index.html\u6240\u5728\u7684\u6587\u4ef6\u5939\u4e2d\u542f\u52a8http-server\u7b49\u5de5\u5177\uff0c\u5c31\u53ef\u4ee5\u5229\u7528system.js\u8fd9\u4e2a\u795e\u5947\u7684\u4e1c\u897f\u8ba9Angular\u8fd0\u884c\u8d77\u6765\uff01\u987a\u4fbf\u4e00\u63d0\uff0cAngular\u9886\u57df\u6709\u4e00\u4e9b\u6253\u5305\u5668\u4f8b\u5982Webpack\u3001Browserify\u3001System.js\u7b49\uff0c\u4f46\u6211\u89c9\u5f97Webpack\u662f\u6700\u5e38\u7528\u7684\u5de5\u5177\u3002\u6709\u4e2aAngular\u7684\u5927\u725b\u66fe\u8bf4System.js\u8fd8\u592a\u65e9\uff01\uff08\u53c2\u8003\uff1aTechFeed Live#2\u62a5\u544a\uff09<\/p>\n<p>\u6709\u4e00\u5f20\u5907\u5fd8\u5355\u53ef\u4f9b\u4f7f\u7528\uff0c\u6240\u4ee5\u4f60\u60f3\u77e5\u9053\u8fd9\u4e2a\u600e\u4e48\u505a\uff1f\u8fd8\u662f\u90a3\u4e2a\u662f\u4ec0\u4e48\uff1f\u2192\u53bb\u67e5\u4e00\u4e0b\u2192\u5b66\u4e60\u8fdb\u5c55\u4f1a\u66f4\u987a\u5229\u3002<br \/>\nhttps:\/\/angular.io\/docs\/ts\/latest\/guide\/cheatsheet.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5bf9\u4e8e\u4f7f\u7528\u8fc7React\u7684\u4eba\u6765\u8bf4\uff0c\u6211\u5c06\u603b\u7ed3React\u4e2d\u7684\u67d0\u4e9b\u6982\u5ff5\u5728Angular 2\u4e2d\u7684\u5bf9\u5e94\u5173\u7cfb\u662f\u600e\u6837\u7684\u3002\u4f5c\u4e3a\u4e00\u4e2a [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-38970","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4e3aReact\u7528\u6237\u63d0\u4f9b\u7684Angular2\u5165\u95e8\u6307\u5357 - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4e3areact\u7528\u6237\u63d0\u4f9b\u7684angular2\u5165\u95e8\u6307\u5357\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4e3aReact\u7528\u6237\u63d0\u4f9b\u7684Angular2\u5165\u95e8\u6307\u5357\" \/>\n<meta property=\"og:description\" content=\"\u5bf9\u4e8e\u4f7f\u7528\u8fc7React\u7684\u4eba\u6765\u8bf4\uff0c\u6211\u5c06\u603b\u7ed3React\u4e2d\u7684\u67d0\u4e9b\u6982\u5ff5\u5728Angular 2\u4e2d\u7684\u5bf9\u5e94\u5173\u7cfb\u662f\u600e\u6837\u7684\u3002\u4f5c\u4e3a\u4e00\u4e2a [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4e3areact\u7528\u6237\u63d0\u4f9b\u7684angular2\u5165\u95e8\u6307\u5357\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-07T14:14:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-29T23:25:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d37f937434c4406c74982\/63-0.png\" \/>\n<meta name=\"author\" content=\"\u97f5, \u79d1\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u97f5, \u79d1\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%b8%bareact%e7%94%a8%e6%88%b7%e6%8f%90%e4%be%9b%e7%9a%84angular2%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%b8%bareact%e7%94%a8%e6%88%b7%e6%8f%90%e4%be%9b%e7%9a%84angular2%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97\/\",\"name\":\"\u4e3aReact\u7528\u6237\u63d0\u4f9b\u7684Angular2\u5165\u95e8\u6307\u5357 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-08-07T14:14:29+00:00\",\"dateModified\":\"2024-04-29T23:25:11+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%b8%bareact%e7%94%a8%e6%88%b7%e6%8f%90%e4%be%9b%e7%9a%84angular2%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%b8%bareact%e7%94%a8%e6%88%b7%e6%8f%90%e4%be%9b%e7%9a%84angular2%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%b8%bareact%e7%94%a8%e6%88%b7%e6%8f%90%e4%be%9b%e7%9a%84angular2%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4e3aReact\u7528\u6237\u63d0\u4f9b\u7684Angular2\u5165\u95e8\u6307\u5357\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e\",\"name\":\"\u97f5, \u79d1\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g\",\"caption\":\"\u97f5, \u79d1\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunke\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%b8%bareact%e7%94%a8%e6%88%b7%e6%8f%90%e4%be%9b%e7%9a%84angular2%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u4e3aReact\u7528\u6237\u63d0\u4f9b\u7684Angular2\u5165\u95e8\u6307\u5357 - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u4e3areact\u7528\u6237\u63d0\u4f9b\u7684angular2\u5165\u95e8\u6307\u5357\/","og_locale":"zh_CN","og_type":"article","og_title":"\u4e3aReact\u7528\u6237\u63d0\u4f9b\u7684Angular2\u5165\u95e8\u6307\u5357","og_description":"\u5bf9\u4e8e\u4f7f\u7528\u8fc7React\u7684\u4eba\u6765\u8bf4\uff0c\u6211\u5c06\u603b\u7ed3React\u4e2d\u7684\u67d0\u4e9b\u6982\u5ff5\u5728Angular 2\u4e2d\u7684\u5bf9\u5e94\u5173\u7cfb\u662f\u600e\u6837\u7684\u3002\u4f5c\u4e3a\u4e00\u4e2a [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u4e3areact\u7528\u6237\u63d0\u4f9b\u7684angular2\u5165\u95e8\u6307\u5357\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-08-07T14:14:29+00:00","article_modified_time":"2024-04-29T23:25:11+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d37f937434c4406c74982\/63-0.png"}],"author":"\u97f5, \u79d1","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u97f5, \u79d1","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%b8%bareact%e7%94%a8%e6%88%b7%e6%8f%90%e4%be%9b%e7%9a%84angular2%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%b8%bareact%e7%94%a8%e6%88%b7%e6%8f%90%e4%be%9b%e7%9a%84angular2%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97\/","name":"\u4e3aReact\u7528\u6237\u63d0\u4f9b\u7684Angular2\u5165\u95e8\u6307\u5357 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-08-07T14:14:29+00:00","dateModified":"2024-04-29T23:25:11+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%b8%bareact%e7%94%a8%e6%88%b7%e6%8f%90%e4%be%9b%e7%9a%84angular2%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e4%b8%bareact%e7%94%a8%e6%88%b7%e6%8f%90%e4%be%9b%e7%9a%84angular2%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%b8%bareact%e7%94%a8%e6%88%b7%e6%8f%90%e4%be%9b%e7%9a%84angular2%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u4e3aReact\u7528\u6237\u63d0\u4f9b\u7684Angular2\u5165\u95e8\u6307\u5357"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e","name":"\u97f5, \u79d1","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g","caption":"\u97f5, \u79d1"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunke\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%b8%bareact%e7%94%a8%e6%88%b7%e6%8f%90%e4%be%9b%e7%9a%84angular2%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/38970","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=38970"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/38970\/revisions"}],"predecessor-version":[{"id":90520,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/38970\/revisions\/90520"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=38970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=38970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=38970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}