Having trouble with scope in side menu example


#1

Hey Guy,

I’m having a little trouble with $scope in the the side menu example. When I use ng-model=“modelExample” on an input field for example, I can’t access it in my js using $scope.modelExample. Has anyone else had a similar problem?

I’m happy to post some of my code if needed.

Thanks,
Tom


#2

It’s bizarre, a function is called but ng-model doesn’t bind. See my code below, the function refreshResults() is called when I submit the form but $scope.search returns as undefined.

.controller('SearchCtrl', function($scope) {
    $scope.refreshResults = function() {
        console.log($scope.search);
    };
})


<ion-view>
    <ion-content class="has-header">
        <form ng-submit="refreshResults()" class="bar bar-header item-input-inset">
            <label class="item-input-wrapper">
                <i class="icon ion-ios7-search placeholder-icon"></i>
                <input type="search" placeholder="Search..." ng-model="search">
            </label>
        </form>
    </ion-content>
</ion-view> 

#3

I solved my issue. I needed to set my ng-model to an object. Here’s more info on what I was doing wrong and the solution http://jimhoskins.com/2012/12/14/nested-scopes-in-angularjs.html


#4

Glad to hear you were able to resolve this! :smile: