{"componentChunkName":"component---src-templates-tags-js","path":"/tags/systemjs/","result":{"data":{"allMarkdownRemark":{"totalCount":1,"edges":[{"node":{"id":"376d7327-803d-548e-b5a5-95a179b4b6ab","html":"<p>I’ve seen many ways to shape an Angular app in different companies. This means when we try to upgrade to Angular 2 some of them might be easy to migrate compared to others.</p>\n<!--more-->\n<p>So why we don’t try to write some code that is easy to migrate even before trying to upgrade???</p>\n<p>According to Angular official website there are a few keys and patterns to follow which lets us make the transition smoother when the time comes. But first let’s discuss why we should upgrade.</p>\n<h2 id=\"why-upgrade\" style=\"position:relative;\"><a href=\"#why-upgrade\" aria-label=\"why upgrade permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Why Upgrade</h2>\n<p>You might have not noticed but Angular 1.x can be very dangerous in the hand of a developer who does not know how stuff works and only wants to get the task done without thinking of the consequences.</p>\n<p>Thinking about all of the watches that will be put in a page plus a code that can be very poor designed is very scary and need to be considered by every team lead or team member specially during code reviews.</p>\n<p>Anyway below you can find a couple of strong reasons on why we should think of moving towards Angular 2:</p>\n<ul>\n<li><strong>Better Performance</strong> - Angular 2 comes with a way faster change detection, template pre-compilation, faster bootstrap time, view caching and plenty other things that make the framework pretty fast.</li>\n<li><strong>Server-side Rendering</strong> - The next version of Angular has been split up into two parts, an application layer and a render layer. This enables us to run Angular in other environments than the browser like Web Workers or even servers.</li>\n<li><strong>More powerful Templating</strong> - The new template syntax is statically analyzable, removes many directives and integrates better with Web Components and other elements.</li>\n<li><strong>Better Ecosystem</strong> - Of course, at the time of writing this article, this is not true. But the Angular 2 ecosystem will eventually be better and more interesting to us in the future.</li>\n</ul>\n<h2 id=\"consider-following-angular-style-guide\" style=\"position:relative;\"><a href=\"#consider-following-angular-style-guide\" aria-label=\"consider following angular style guide permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Consider Following Angular Style Guide</h2>\n<p>The <a href=\"https://angular.io/guide/styleguide\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Angular Style Guides</a> is a collection of useful patterns and practices that helps developers write readable, maintainable, cleaner and efficient code.  It contains a wealth of information about how to write and organize Angular code - and equally importantly - how <strong>not</strong> to write and organize Angular code.</p>\n<p>In writing Angular 2, the team members tries to maintain the <strong>good</strong> parts while get rid of the <strong>bad</strong> ones. Although there are way more than that to be said but general idea is that it should be a framework which people can rely on in their production environments.</p>\n<p>There are a few particular rules in there that I would like to bold here:</p>\n<ol>\n<li>There should be one component per file, which let’s us not only have maintainable code but also makes it easy to migrate them one at a time regardless of the destination framework (e.g Angular 2 or React).</li>\n<li>The <a href=\"https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#folders-by-feature-structure\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Folders-by-Feature Structure</a> and <a href=\"https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#modularity\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Modularity</a> rules define similar principles on a higher level which tell us different parts of the app should be placed in different folders and modules.</li>\n</ol>\n<h2 id=\"dont-choose-anything-else-than-amodule-loader\" style=\"position:relative;\"><a href=\"#dont-choose-anything-else-than-amodule-loader\" aria-label=\"dont choose anything else than amodule loader permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Don’t choose anything else than a module loader</h2>\n<p>JavaScript admittedly has plenty of flaws, but one of the largest and most prominent is the lack of a module system: a way to split up your application into a series of smaller files that can depend on each other to function correctly. While doing so having large number of smaller files is better than small number of large files, but it does not work well if we have to load them all into Html file by script tags.</p>\n<p>Because of dependencies that exists with this structure the need for a module loader is vital. There are a couple of good tools out there like Webpack, Browserify or SystemJs which pretty much are making use of typescript built in module system.</p>\n<p>By specifying <em>import</em> and <em>export</em> in modules we define which modules can be exported and which ones depend on another.</p>\n<h2 id=\"we-should-migrate-to-typescript\" style=\"position:relative;\"><a href=\"#we-should-migrate-to-typescript\" aria-label=\"we should migrate to typescript permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>We should migrate to TypeScript</h2>\n<p>Because Angular 2 itself is recommending to use that, we should migrate our current code to TypeScript even before starting the migration so there would be one less concern when the day comes. By just importing TypeScript compiler and renaming files from <code class=\"language-text\">*.js</code> to <code class=\"language-text\">*.ts</code> wouldn’t be enough. You have to at least follow some of the ES6 new features which you can find here (<a href=\"/2016/07/06/es6-new-features-part-i/\">part 1</a>, <a href=\"/2016/07/07/es6-new-features-part-ii/\">part 2</a>, <a href=\"/2016/07/11/es6-new-features-part-iii/\">part 3</a>). That’s why I started with them as one of the most important prerequisites of the process.</p>\n<h2 id=\"directives-as-components\" style=\"position:relative;\"><a href=\"#directives-as-components\" aria-label=\"directives as components permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Directives as Components</h2>\n<p>Angular 2 is heavily dependent on Components which basically are a portion of UI whose got a special logic behind that. The UI part can be a template but by containing them in a <em>directive</em> you can make sure that migration process would be easier.</p>\n<p>Well that somehow makes things in perspective but to be more precise a directive which contains the template, controller and bindings required to deliver that functionality. Based on Angular website a directive should cover bellow items to be Angular 2 compatible:</p>\n<ul>\n<li><code class=\"language-text\">restrict: 'E'</code>. Components are usually used as elements.</li>\n<li><code class=\"language-text\">scope: {}</code> - an isolate scope. In Angular 2, components are always isolated from their surroundings, and we should do this in Angular 1 too.</li>\n<li><code class=\"language-text\">bindToController: {}</code>. Component inputs and outputs should be bound to the controller instead of using the <code class=\"language-text\">$scope</code>.</li>\n<li><code class=\"language-text\">controller</code> and <code class=\"language-text\">controllerAs</code>. Components have their own controllers.</li>\n<li><code class=\"language-text\">template</code> or <code class=\"language-text\">templateUrl</code>. Components have their own templates.\r\nAlso it is mentioned that the directive should not use <code class=\"language-text\">compile</code>, <code class=\"language-text\">replace: true</code>, <code class=\"language-text\">priority</code> and <code class=\"language-text\">terminal</code>.</li>\n</ul>\n<p>This is how a ideal directive looks like:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"17270641035194888000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied to clipboard ✅\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`export function myDetailDirective() {\r\n  return {\r\n    restrict: 'E',\r\n    scope: {},\r\n    bindToController: {\r\n      myInfo: '=',\r\n      getCreditCardInfo: '&',\r\n    },\r\n    template: \\`\r\n      <h2>My name is: {{ctrl.myInfo.myName}}</h2>      \r\n      <button ng-click=&quot;ctrl.onClick()&quot;>Get card info</button>\r\n    \\`,\r\n    controller: function() {\r\n      this.onClick = () => {\r\n        this.getCreditCardInfo({ name: this.myInfo })\r\n      }\r\n    },\r\n    controllerAs: 'ctrl',\r\n  }\r\n}`, `17270641035194888000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                Copy<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-javascript line-numbers\"><code class=\"language-javascript\"><span class=\"token keyword\">export</span> <span class=\"token keyword\">function</span> <span class=\"token function\">myDetailDirective</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\r\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\r\n    <span class=\"token literal-property property\">restrict</span><span class=\"token operator\">:</span> <span class=\"token string\">'E'</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">scope</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">bindToController</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\r\n      <span class=\"token literal-property property\">myInfo</span><span class=\"token operator\">:</span> <span class=\"token string\">'='</span><span class=\"token punctuation\">,</span>\r\n      <span class=\"token literal-property property\">getCreditCardInfo</span><span class=\"token operator\">:</span> <span class=\"token string\">'&amp;'</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">template</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\r\n      &lt;h2>My name is: {{ctrl.myInfo.myName}}&lt;/h2>      \r\n      &lt;button ng-click=\"ctrl.onClick()\">Get card info&lt;/button>\r\n    </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token function-variable function\">controller</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\r\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onClick</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\r\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getCreditCardInfo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>myInfo <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\r\n      <span class=\"token punctuation\">}</span>\r\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">controllerAs</span><span class=\"token operator\">:</span> <span class=\"token string\">'ctrl'</span><span class=\"token punctuation\">,</span>\r\n  <span class=\"token punctuation\">}</span>\r\n<span class=\"token punctuation\">}</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></pre></div>\n<p>If you are already using Angular 1.5 you should use its Component API which helps you define such directives. This API enforces you to use controllerAs syntax and also has good default values for <code class=\"language-text\">scope</code> and <code class=\"language-text\">restrict</code>.</p>\n<p>The above directive looks like below:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"78695649902506080000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied to clipboard ✅\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`export const myDetail = {\r\n  bindings: {\r\n    myInfo: '=',\r\n    getCreditCardInfo: '&',\r\n  },\r\n  template: \\`\r\n    <h2>My name is: {{ ctrl.myInfo.myName }}</h2>\r\n    <button ng-click=&quot;ctrl.onClick()&quot;>Get card info</button>\r\n  \\`,\r\n  controller: function() {\r\n    this.onClick = () => {\r\n      this.getCreditCardInfo(this.myInfo)\r\n    }\r\n  },\r\n}`, `78695649902506080000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                Copy<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-javascript line-numbers\"><code class=\"language-javascript\"><span class=\"token keyword\">export</span> <span class=\"token keyword\">const</span> myDetail <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\r\n  <span class=\"token literal-property property\">bindings</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\r\n    <span class=\"token literal-property property\">myInfo</span><span class=\"token operator\">:</span> <span class=\"token string\">'='</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">getCreditCardInfo</span><span class=\"token operator\">:</span> <span class=\"token string\">'&amp;'</span><span class=\"token punctuation\">,</span>\r\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\r\n  <span class=\"token literal-property property\">template</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\r\n    &lt;h2>My name is: {{ ctrl.myInfo.myName }}&lt;/h2>\r\n    &lt;button ng-click=\"ctrl.onClick()\">Get card info&lt;/button>\r\n  </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\r\n  <span class=\"token function-variable function\">controller</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\r\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onClick</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\r\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getCreditCardInfo</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>myInfo<span class=\"token punctuation\">)</span>\r\n    <span class=\"token punctuation\">}</span>\r\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\r\n<span class=\"token punctuation\">}</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></pre></div>\n<p>{: .box-note}\r\n<strong>Note:</strong> I had to remove the $ from above code because of mark down rendering errors.</p>\n<h2 id=\"upgrade-using-the-given-adapter\" style=\"position:relative;\"><a href=\"#upgrade-using-the-given-adapter\" aria-label=\"upgrade using the given adapter permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Upgrade using the given Adapter</h2>\n<p>When everyone was thinking of how to deal with breaking changes introduced in the very initial introduction of Angular 2, they were trying to tackle this issue to make it easier to upgrade. They came up with <em>ng-upgrade,</em> an awesome Adapter which let’s you mix Angular 1 and 2 code together.</p>\n<p>This way, (if you’ve already done the steps mentioned earlier) you can start migrating your components one by one and not worry about what happens with current state of the product. The story gets more exciting as directives and services in one application can interact with the other one which is amazing (and also <strong>dangerous</strong> in the wrong hands).</p>\n<p>In order for this to happen four things need to be in place:</p>\n<ul>\n<li><strong>Dependency Injection</strong> - Exposing Angular 2 services into Angular 1 components and vice-versa.</li>\n<li><strong>Component Nesting</strong> - Angular 1 directives can be used in Angular 2 components and Angular 2 components can be used in Angular 1 directives.</li>\n<li><strong>Content Projection / Transclusion</strong> - Angular 1 components transclude Angular 2 components and Angular 2 component project Angular 1 directives.</li>\n<li><strong>Change Detection</strong> - Angular 1 scope digest and change detectors in Angular 2 are interleaved.</li>\n</ul>\n<p>With these four things being interoperable, we can already start upgrading our applications component by component. Routing is another part that can help but is not necessarily mandatory, since we can totally stick with any Angular 1 routing system while upgrading.</p>\n<p>An example is shown in the following code to illustrate what we talked about:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"68112329166238730000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied to clipboard ✅\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`import { UpgradeAdapter } from '@angular/upgrade'\r\n\r\nvar adapter = new UpgradeAdapter()\r\nvar app = angular.module('myApp', [])\r\n\r\nadapter.bootstrap(document.body, ['myApp'])`, `68112329166238730000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                Copy<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-javascript line-numbers\"><code class=\"language-javascript\"><span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> UpgradeAdapter <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'@angular/upgrade'</span>\r\n\r\n<span class=\"token keyword\">var</span> adapter <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">UpgradeAdapter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\r\n<span class=\"token keyword\">var</span> app <span class=\"token operator\">=</span> angular<span class=\"token punctuation\">.</span><span class=\"token function\">module</span><span class=\"token punctuation\">(</span><span class=\"token string\">'myApp'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\r\n\r\nadapter<span class=\"token punctuation\">.</span><span class=\"token function\">bootstrap</span><span class=\"token punctuation\">(</span>document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'myApp'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span><span></span><span></span></span></pre></div>\n<p>Cool now we can take advantage of ng-upgrade in our Angular 1 app and start migrating to Angular 2. Of course there are a lot more to do but you get the idea.</p>\n<h2 id=\"user-service-instead-of-factory\" style=\"position:relative;\"><a href=\"#user-service-instead-of-factory\" aria-label=\"user service instead of factory permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>User service instead of factory</h2>\n<p>If you are planning to upgrade to Angular 2 and also the language you are using like ES6, it completely makes sense that you should use <code class=\"language-text\">.service()</code> instead of <code class=\"language-text\">.factory()</code> where a service can be potentially a class.</p>\n<p>In Angular 2, a service is also just a class, so this seems like a logical step to undertake.</p>\n<p>I think that’s enough for making you think about the steps you have to take to be ready take off. For a full documentation on preparation you can read <a href=\"https://angular.io/guide/upgrade\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">this page</a>.</p>","timeToRead":6,"frontmatter":{"title":"Preparation steps for Angular 2 migration","unformattedDate":"2016-07-13T00:00:00.000Z","date":"Jul 13, 2016","path":"/preparation-steps-for-angular-2-migration/","author":"Yaser Adel Mehraban","tags":["angular","angular 2","component","directive","migration","systemjs","typescript","webpack"],"thumbnail":{"childImageSharp":{"gatsbyImageData":{"layout":"constrained","placeholder":{"fallback":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAARCAIAAABSJhvpAAAACXBIWXMAAAsTAAALEwEAmpwYAAADZElEQVR42oVTe0xTVxg/dSgSFp0yX5GoFCq9LaXQW4faSTSKQyFxyx6JhEVRY3wmmhiZbCbL1Jio+8eZGh/IFheNr/BSRtZN2lrAYQtiH5Tb3l4ot9CC0NFiaXsfx3NBnUYXv3O+c05y8vt+33fO7wMQQp5lIctBHg04ysRdBOELDMbhhPE8ukULfJeByW2M5ymabq+923HwSOuXpTVbdv6lvdBptgRCIRb+r4EYwzzWG9qOHrcWfuVZumxIjBNVv99dsbZhobQ2b0192S7dxUqPywU5nmNYnmHha1mAMOQtuw/658v8mXl9i3OGyvYTI8O1h440irMbM/E/U7Hq7OXtFvNkBQKC41EIHpUpMENoO3GaTlPR2fnetNxRnZ5o1FVXXvlj5bp7UlUDmpr1xPlr/s2HXQeOhdo6uVhs4i2ECVAE68UqLwKL8f7Pvw17++wKTc1PJxrKjxrmYJaPcWeSigRS5wyF4UPMmIR1fPqN99SFZ04SZSI8mL2mvjcdpxcph67fCZOUY/P2usMVnZoSCsipKbmeqSoXWBrS3uja8Z1elG5MkukTJMbpGP3LbwLYZWohM9QD+cVBrzfc/qQbpa3V2iSfeUCWO1HlBlk9C1bDsciw7oFhWqYpRdU8b9l9sAjxC+BeRxchzRv59dqIzTGQrrZJ1PUyvCMFp0Q5ZCJOAPHwD2djFB11ex+vLdV/IDHNVqEogzfvCWAf7bPmF42ePjewr7w/Q21TaOoUn5jn4j2iHLcom0xWsx4fVbSjX3t18HZjE1himpVrTJYH9Q8FcJRhOv9usnxRSi3MGkLM2PI6ibJllpxKEGgDWytgnKVLy/vOXObGo21YAaJtTlFFCArAlz/oD4csN245NpVYM/DqgmJTyV5PQq5bJB83mlnf4LjZHrLYuEi096T2Pkh9mLGGCY6+kCc/4UiJvbTPdOmK3WH/12x1g3T/14f4aKxPUuwE8iYgJvb/yI49a0nVPFJs4ONx8Eprr9TPcsKBDQyTicpAWUXwZCUJZM6pSsN0rHXxqsD1un9kBU82bvuvMd4IgZwT1BezEgOFewiwhBRh3Um46aOcpilphmSM+v7n+NPgO8BvW0TX2q/Z0gWkD2Yqu3dWRFw9kyTvAyN+ZqIjx2PBquoRXfOL3F721nMefM73orsXWAAAAABJRU5ErkJggg=="},"backgroundColor":"transparent","images":{"fallback":{"src":"/static/b2d786120012ce828f21ed0d786956d2/2f861/migration.png","srcSet":"/static/b2d786120012ce828f21ed0d786956d2/2f861/migration.png 718w","sizes":"(min-width: 718px) 718px, 100vw"},"sources":[{"srcSet":"/static/b2d786120012ce828f21ed0d786956d2/dd172/migration.webp 718w","type":"image/webp","sizes":"(min-width: 718px) 718px, 100vw"}]},"width":718,"height":605}}}}}}]}},"pageContext":{"tag":"systemjs"}},"staticQueryHashes":[],"slicesMap":{}}