<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Slaven Kopic</title>
    <description>The latest articles on DEV Community by Slaven Kopic (@slaven3kopic).</description>
    <link>https://dev.to/slaven3kopic</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F545276%2Fa101f630-def4-4fb0-9449-394bf6637cf3.jpeg</url>
      <title>DEV Community: Slaven Kopic</title>
      <link>https://dev.to/slaven3kopic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/slaven3kopic"/>
    <language>en</language>
    <item>
      <title>AngularJS to Angular</title>
      <dc:creator>Slaven Kopic</dc:creator>
      <pubDate>Tue, 22 Dec 2020 14:53:38 +0000</pubDate>
      <link>https://dev.to/slaven3kopic/angularjs-to-angular-2ni6</link>
      <guid>https://dev.to/slaven3kopic/angularjs-to-angular-2ni6</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Recently I tried to upgrade AngularJS application to Angular (v11.0.5). In this post I will describe important steps how AngularJS can be upgraded to Angular.&lt;/p&gt;

&lt;h3&gt;
  
  
  Convert &lt;code&gt;.js&lt;/code&gt; files to &lt;code&gt;.ts&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;If you are using AngularJS with JavaScript, first you need to convert all the files to Typescript by changing the extension to &lt;code&gt;.ts&lt;/code&gt;. Since TypeScript is just an extension of JavaScript, conversion should be done without any issues.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add TypeScript
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Install TypeScript by running &lt;code&gt;npm i typescript&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create &lt;code&gt;tsconfig.json&lt;/code&gt; file with following &lt;a href="https://raw.githubusercontent.com/slaven3kopic/angularjs2angular/main/tsconfig.json"&gt;content&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Add Webpack and Webpack Dev Server
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Install Webpack by running &lt;code&gt;npm i webpack webpack-dev-server -d&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create &lt;code&gt;webpack.config.js&lt;/code&gt; file with following &lt;a href="https://raw.githubusercontent.com/slaven3kopic/angularjs2angular/main/webpack.config.js"&gt;content&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Webpack plugins used in &lt;code&gt;webpack.config.js&lt;/code&gt; also need to be installed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Load TypeScript
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;create &lt;code&gt;main.ts&lt;/code&gt; with following &lt;a href="https://raw.githubusercontent.com/slaven3kopic/angularjs2angular/main/app/main.ts"&gt;content&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;main.ts&lt;/code&gt; is used as entry file for Webpack.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Add scripts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Add scripts to run and build the app in the &lt;code&gt;package.json&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;Scripts can be found in the &lt;a href="https://raw.githubusercontent.com/slaven3kopic/angularjs2angular/main/package.json"&gt;package.json&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Add Angular dependencies
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Install Angular dependencies by running &lt;code&gt;npm i @angular/animations @angular/common @angular/compiler @angular/compiler-cli @angular/core @angular/forms @angular/platform-browser @angular/platform-browser-dynamic @angular/router @angular/upgrade zone.js rxjs&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Bootstrap hybrid app
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;a href="https://angular.io/api/upgrade/static/UpgradeModule"&gt;UpgradeModule&lt;/a&gt; to bootstrap hybrid app.&lt;/li&gt;
&lt;li&gt;Example of how to bootstrap hybrid app can be found &lt;a href="https://github.com/slaven3kopic/angularjs2angular/blob/main/app/main.ts"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Migrate services
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Migrate services one by one to Angular.&lt;/li&gt;
&lt;li&gt;In transition period use &lt;code&gt;downgradeInjectable()&lt;/code&gt; to run Angular services inside AngularJS.&lt;/li&gt;
&lt;li&gt;Example of how to migrate a service and use it in AngularJS can be found &lt;a href="https://raw.githubusercontent.com/slaven3kopic/angularjs2angular/main/app/core/phone/phone.service.ts"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Migrate components and modules
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Migrate all components and modules to Angular.&lt;/li&gt;
&lt;li&gt;In transition period use &lt;code&gt;downgradeComponent()&lt;/code&gt; and &lt;code&gt;downgradeModule()&lt;/code&gt; to run Angular components and modules in AngularJS.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Remove AngularJS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Remove downgrades (&lt;code&gt;downgradeInjectable()&lt;/code&gt;, &lt;code&gt;downgradeComponent()&lt;/code&gt;, &lt;code&gt;downgradeModule()&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Remove all AngularJS dependencies.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Running
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Run app by executing the following command &lt;code&gt;npm start&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example project
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Example project can be found &lt;a href="https://github.com/slaven3kopic/angularjs2angular"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Disclaimer
&lt;/h3&gt;

&lt;p&gt;Only the steps I personally found important to emphasize are written. Example project is not fully complete.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>typescript</category>
      <category>webpack</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
