How to change scope data in controller?

Posted by Derooie on Stack Overflow See other posts from Stack Overflow or by Derooie
Published on 2014-06-09T09:20:53Z Indexed on 2014/06/09 9:24 UTC
Read the original article Hit count: 284

Filed under:

I am a real newbie at angular. I created something now which will let me retrieve and add items via angular and get/put them in mongodb. I use express and mongoose in the app

The question is, how can i modify the data before it reaches the DOM in the controller. In this example i have created a way to retrieve data, and i get it exactly as it is stored in mongodb. What i would like is that the field where i store 1 or 0 in the database, to be shown as text. So if mongo has a value 1 i get "the value in mongo is 1" and when the field has a value of 0 get "the value is zero". (just as an example, i like other texts, but it illustrate what i want)

I post my controller, html and current output. Any help would be appreciated.

Controller

function getGuests($scope, $http) {
    $scope.formData = {};
    $http.get('/api/guests')
        .success(function(data) {
            $scope.x = data;

        })
        .error(function(data) {
            console.log('Error: ' + data);
        }); 

}

HTML

<div ng-controller="getGuests">
    <div ng-repeat="guest in x">
        {{ guest.voornaam }} {{ guest.aanwezig }}
    </div>
</div>

The current scope output, what i see in HTML. I like to change only the value of "aanwezig" in case the value of aanwezig is 0 or 1.

firstname1 1
firstname2 0

Something else, but would be great to learn, is how i can do a specific mongodb query by the push of a button and get that result.

© Stack Overflow or respective owner

Related posts about angularjs