0
votes

I have a fully working Ionic app where I've added angular switches to manipulate certain divs in the view.

The problem occurs on the ion-footer-bar. It always defaults to facebook (index 0) and just completely ignores the instagram ng-switch-when. In the chrome developer I can clearly see the ng-switch in action, yet the erroneous behavior is persistent, no matter what I do.

I've tried all different kind of changes to no avail, I'm starting to think it has to do with how Ionic builds it's ion-content & ion-footer-bar elements (?)

HTML

<ion-content>
    <select ng-model="selectedNetwork" ng-change="setSelected(selectedNetwork.id)" data-ng-options="availableNetwork as availableNetwork.label for availableNetwork in availableNetworksForSelect track by availableNetwork.id">
    </select>

    //*******Please note that These two divs work perfectly*********
    <div ng-switch = "selectedNetwork.id" class="">
        <div ng-switch-when = "facebook" class="" >
            <span>I am Facebook</span>
        </div>
        <div ng-switch-when = "instagram" class="">
            <span>I am instagram</span>
        </div>
    </div>

</ion-content>
<ion-footer-bar ng-switch = "selectedNetwork.id">
    <div ng-switch-when = "facebook" class="" >
        <span>I am Facebook</span>
    </div>
    <div ng-switch-when = "instagram" class="">
        <span>I am instagram</span>
    </div>
</ion-footer-bar>

This is the controller

$scope.availableNetworksForSelect = [{
                                id: 'facebook',
                                label: 'This is Facebook'
                            }, {
                                id: 'instagram',
                                label: 'This is instagram'
                            }];

$scope.selectedNetwork = $scope.availableNetworksForSelect[0];

EDIT: per request, here is setSelected();

$scope.setSelected = function (network) {
    console.log('setSelected', network)
    $scope.selectedTab = network;
    $scope.translationData = {
        network: network.charAt(0).toUpperCase() + network.substring(1)
    };
    var currentTabNetworkTerms;
    if (!_.isUndefined($scope.baba.networks)) {
        currentTabNetworkTerms = _.find($scope.baba.networks, {code: network}).actions;
        $scope.currentTabNetworkActions = _.sortBy(currentTabNetworkTerms, function (term) {
            if (term.name == "post") {
                return 0;
            }
            return 1;
        });
    }
}
1
Your controller is probably bound to the ion-content directive, so the ion-footer-bar falls outside of its scope - devqon
@devqon - what would be best practice to fix this? - DudeOfLayers

1 Answers

0
votes

don't use ng-switch as attribute of ion-footer-bar updated code is

<ion-footer-bar> 
    <ng-switch on="selectedNetwork.id">
        <div ng-switch-when = "facebook" class="" >
            <span>I am Facebook</span>
        </div>
        <div ng-switch-when = "instagram" class="">
            <span>I am instagram</span>
        </div>
    </ng-switch>
</ion-footer-bar>