Search code examples
ionic-frameworkerror-handlingios9

ionic ios9 Error: [ng:areq] Argument ‘TabCtrl’ is not a function, got undefined


I get this error in only ios 9. It works fine in ios 10 and android and browser. I really don't understand why this happen in only ios 9

Note: when I clean the codes inside contoller, it works fine.

My code:

angular.module('starter')

.controller('TabsCtrl', function($scope, $rootScope, $ionicPlatform, $state, $cordovaCamera, $cordovaFileTransfer, $cordovaFile, $ionicLoading, $ionicTabsDelegate, $ionicModal, $ionicActionSheet, AuthService, httpService, imageService, API) {

    // initialize tab's modal page
    $scope.profile_picture = "img/profile.jpg";
    $scope.social = {};
    $scope.pic = {};
    $ionicPlatform.onHardwareBackButton(function(event){
        if (window.localStorage['is_user_info_compelete'] != 1) {
            ionic.Platform.exitApp();
        }
    })

    window.localStorage['is_user_info_compelete'] = 1;


    $scope.getStateByServer = function() {
        httpService.handleRequest(new Array(), API.url+'state/getAll', function() {}, function() {}, '').then(function(result) {
            $scope.$broadcast('scroll.refreshComplete');
            $rootScope.states = result.data[0];
            $rootScope.cities = result.data[1];
            $scope.states = $rootScope.states;
            $scope.cities = $rootScope.cities;
            $scope.citiesByState = [];
        });
    }
    $scope.getStateByServer();




    // Modal
    modalOptions = {scope: $scope, animation: 'slide-in-up', backdropClickToClose: false, hardwareBackButtonClose: false};
    $ionicModal.fromTemplateUrl('my-modal.html', modalOptions).then(function(modal) {
        $scope.modal = modal;
        if (window.localStorage['is_user_info_compelete'] != 1) {
            setTimeout(function() {
                $scope.modal.show();
            }, 1200);
        }
    });


    /**
     * Save all information of the model
     * Use json_decode for moreData in php like: json_decode($this->input->post("data"));
     * index 'data' is the name of object in httpService.handleFileSender
     */
    $scope.saveSocialInfo = function(social, city) {

        if (!$scope.socialValidate(social, city)) {return false;}

        data = {picture:$scope.profile_picture, city:city, social:social, uploadDirectory: 'upload/profile'};
        moreData = [
            {token:window.localStorage['yourTokenKey']},
            {social:social}
        ];

        $ionicLoading.show();
        httpService.handleFileSender(data, moreData, API.url+'social/save/t2AkQ6df0W').then(function(result){
            $ionicLoading.hide();
            if (JSON.stringify(parseInt(result.response)) == 1) {
                window.localStorage['is_user_info_compelete'] = 1;
                $scope.modal.hide();
            }
            else {
                httpService.popup('خطا', 'ارسال انجام نشد. لطفا مجددا تلاش نمایید.')
            }
        })
    }


    // Action Sheet
    $scope.showActionSheet = function(indexPic = false, width = 500, height = 500, allowEdit = true) {

        var hideSheet = $ionicActionSheet.show({
            buttons: [
                {text: 'گرفتن عکس'},
                {text: 'انتخاب از گالری'}
            ],
            destructiveText: 'پاک کردن',
            titleText: 'انتخاب یا گرفتن عکس',
            cancelText: 'لغو',
            destructiveButtonClicked: function() {
                $scope.profile_picture = "img/profile.jpg";
                return true;
            },
            buttonClicked: function(index) {
                option = { width:width, height:height, allowEdit:allowEdit, quality:80 }
                imageService.getImage(index, option).then(function(imageURL) {
                    if (imageURL) {
                        $scope.profile_picture = imageURL;
                        if (indexPic) {$scope.pic[indexPic] = imageURL;}
                    }
                })
                return true;
            }
        });
    };



    $scope.socialValidate = function(social, city) {
        var title = 'خطا.';
        if ($scope.profile_picture == "img/profile2.jpg") {
            httpService.popup(title, 'اطفا تصویر خود را انتخاب نمایید.');
            return false;
        }
        if (!httpService.validateObject(social)) {
            httpService.popup(title, 'حداقل یکی از شبکه های اجتماعی را باید پر کنید.');
            return false;
        }
        if (!city) {
            httpService.popup(title, 'اطفا شهر خود را انتخاب کنید.');
            return false;
        }
        return true;
    }


    // Handle tabs swipe
    $scope.goForward = function () {
        var selected = $ionicTabsDelegate.selectedIndex();
        if (selected != -1) {
            $ionicTabsDelegate.select(selected + 1);
        }
    }
    $scope.goBack = function () {
        var selected = $ionicTabsDelegate.selectedIndex();
        if (selected != -1 && selected != 0) {
            $ionicTabsDelegate.select(selected - 1);
        }
    }
    $scope.go = function(state) {
        $state.go(state);
    }
    $scope.destroySession = function() {
        AuthService.logout();
    };


    // Get cities by state
    $scope.getCities = function(mystate) {
        $scope.citiesByState = [];
        $scope.arr = [];
        for (var i = 0; i < $scope.cities.length; i++) {
            if ($scope.cities[i].stateID == mystate) {
                $scope.arr.push($scope.cities[i]);
            }
        }
        $scope.citiesByState = $scope.arr;
    }


})

Solution

  • Oh my god. After struggling for some days, finally I found out the solution. I'm using default function parameters. This is supported from ES6/ES2015. As I used this syntax:

    $scope.showActionSheet = function(indexPic = false, width = 500, height = 500, allowEdit = true) {
    }
    

    ios 9 may not supporting this.