Wednesday, February 20, 2019

AngularJS Upgrade (1.4 to1.7)


Step 1. In the command prompt, go to the project folder and run the following command
a. bower init ( it will create a new bower.json file, if already have bower.json file in the same folder remove and run this command)
                b.  bower update ( in the same command prompt run this command. It will update the angular and dependent library)

Step2: uppercase and lowercase methods are removed. Reference link
Due that we will get he error message as follows
Uncaught TypeError: b.lowercase is not a function
For workaround we can add following code in app.js file
angular.lowercase=function(string){
  return (typeof string === 'string') ? string.toLowerCase() : string;
 };
angular.uppercase=function(string){
 return (typeof string === 'string') ? string.toUpperCase() : string;
 };
Step3:  After upgrade we will get this error Error: transition superseded 
To resolve this error upgrade angular-ui-router
a.find and update the version of angular-ui-router in bower.json file
 "angular-ui-router": "~0.4.2",
b.  in the command prompt run the following command in the project folder
bower update angular-ui-router

Step 4 .success and .error are removed from angular 1.7, use .then and .catch as follows
find the following each text
.success(function(data, status, headers, config) {
.success(function(data, status, headers, config){
Replace with following text
.then(function(response) {
       var data = response.data;
        var status = response.status;
        var headers = response.headers;
        var config = response.config;
same as the above repeat for following. Find following text one by one
.error(function(data, status, headers, config) {
.error(function(data,status, headers, config){
Replace with following text
.catch(function(response) {
                var data = response.data;
        var status = response.status;
        var headers = response.headers;
        var config = response.config;
Step 5  Error: orderBy:notarray Value is not array-like
[orderBy:notarray] Expected array but received: {"signed":"Completed","sent":"In Progress","draft":"Draft","cancelled":"Cancelled"}
https://code.angularjs.org/1.7.7/docs/error/orderBy/notarray?p0=%7B%22signed%22:%22Completed%22,%22sent%22:%22In%20Progress%22,%22draft%22:%22Draft%22,%22cancelled%22:%22Cancelled%22%7D

in the view file use toArray:false