How to migrate/upgrade from angularJs library to angular CLI

416 views Asked by At

I initially build my web app using angularJs library not the cli. I am trying to dual boot or migrate to angular2 but can't seem to find any suitable way to do the migration without having to rewrite my code from scratch.

I tried looking at the angular documentation Official Guide1 and official guide2 but they explained it in regards of using the cli initially in angularJs but my web app was not build with the cli rather the library download.

I also tried following this guide but still it is based on migrating from angularjs cli to angular cli.

Can someone point me to a link or help with best way to migrate my angularJS library to angular cli or best solution to dual boot instead.

Also, is it possible to download angular2 library as it is in angular1?

1

There are 1 answers

0
Cito On BEST ANSWER

What I did on mine is follow the instructions on Running angular1 and angular2 side by side

  • I created a new angular 6 application using the angular CLI
  • I created a folder under the src directory called ng1
  • Copied all the angualr1 files into the ng1 director created
  • I migrate all my angular1 JS dependencies on the index.html into the angular.json of the angular2 under the scripts.
    "scripts": [
              "src/ng1/part-to/your-javascript-directory/jquery.min.js"
    ]
  • I also copied all the angular1 CS dependencies on the index.html into the angular.json of the angular2 under the styles
    "styles": [
              "src/styles.css"
     ]
  • I also add the ng1 directory I earlier created in the assets part of the angular2 angular.json file
    "assets": [
              "src/favicon.ico",
              "src/assets",
              "src/ng1"
            ]

The key here angular1 will have to be copied into angualr2. The above is the basic for preparing your angular1 project to dual boat inside angular2. There is more but follow the instructions on the link I posted above and your app will both run side by side. Hope this help