Not defined Errors after upgrade

Hello!

After my last ionic update (didnt updated for a while), I have tried to launch my app, And I have many Errors while I’m using in some of my app’s functions.
Here is one of the errors I have after, I’ve updated ionic:

Error: updateUserDetails is not defined
$scope.register/<@http://localhost:8100/js/controls/loginCntrls.js:126:21
processQueue@http://localhost:8100/lib/ionic/js/ionic.bundle.js:27879:28

and here is my login controller:

angular.module(‘starter.controllers’)
.controller(‘loginCtrl’, function($scope, $rootScope, $state, $fbHelper, $ionicLoading, $uiHelper, $api, $ionicHistory, $parsePush) {

    $scope.user = {
        email: "",
        password: ""
    };
    function handleInputError(emailVal, passwordVal){
        var errorMsg = '';
        if(!emailVal){
            errorMsg = 'Please insert a valid email address';
        } else if(!passwordVal) {
            errorMsg = 'Please insert your password';
        }
        if(errorMsg) {
            $uiHelper.popError("", errorMsg,  function(){});
        }
    }
    function goToFeed(){
        $state.go('app.feeds.latest', {type: "getLatestQuestions", reload: true});
    }
    function updateUserDetails(data){
        $rootScope.$broadcast('user:updated',{userId : data._id, userPicture: data.picture, userName: data.name, gender: data.gender});
    }

.controller(‘registerCtrl’, function ($scope, $rootScope, $state, $ionicLoading, $uiHelper, $api, $ionicHistory, $parsePush) {
console.log(“init registerCtrl”);

    $scope.user = {
        email: "",
        nickname: "",
        password: "",
        verify: "",
        gender: "m"
    };
    function handleInputError(passwordVal, verifyVal){
        var errorMsg = '';
        if($scope.user.email == undefined){
            errorMsg = 'Please insert a valid email address';
        } else if(passwordVal && verifyVal &&  passwordVal != verifyVal){
            errorMsg = 'Password do not match';
        } else {
            errorMsg = 'Missing details';
        }
        if(errorMsg) {
            $uiHelper.popError("", errorMsg,  function(){});
        }
    }
    $scope.register = function($event){
        $event.target.blur();
        var emailVal = $scope.user.email,
            nicknameVal = $scope.user.nickname,
            passwordVal = $scope.user.password,
            verifyVal = $scope.user.verify,
            genderVal = $scope.user.gender;
        if(!emailVal || !passwordVal ||  !nicknameVal || !verifyVal || !genderVal || passwordVal!= verifyVal  ){
            handleInputError(passwordVal, verifyVal);
            return;
        }
        $ionicLoading.show();
        $api.register(emailVal, nicknameVal, passwordVal, genderVal).then(function(data){
            if(data && data.error){
                $uiHelper.popError("", data.error, function(){});
            } else if(data && data._id){
                updateUserDetails(data.user); //HERE is the error I have
                $ionicHistory.nextViewOptions({disableBack: true});
                $parsePush.initParseNotifications();
                goToFeed()
            }
            $scope.user.email = "";
            $scope.user.gender = "m";
            $scope.user.nickname = "";
            $scope.user.password = "";
            $scope.user.verify = "";
            $ionicLoading.hide();
        });
    }
});

as you can see, I have two controllers under the same file, and I’m trying to call a function that exist on the first controller, from the second controller (It used to work, and today its gives me the error).

I have tried to move this function to external service and call this service with the function, and its working, but that means I will have to change my entire project and move everything (Variables, and functions).
did you reproduce such issue? any idea how can I fix it?

Thank you!

Hello,

I didn’t do something like that, so I cannot reproduce your issue. Each controllers have its own context, that’s why you cannot use one function from another.
The services are here to do what your are looking for, this is the best way to do it.

In the other hand, you can put your methods at the top of your file. Then the functions will be available in the two controllers.

I hope this will help you.

So you were right!, I have added a new Login service, added all dependencies to this service, Everything is working perfect right now.
Thank you!

Happy, I could help :slight_smile: