javascript - How to change scope data in controller? -


i real newbie @ angular. created let me retrieve , add items via angular , get/put them in mongodb. use express , mongoose in app

the question is, how can modify data before reaches dom in controller. in example have created way retrieve data, , stored in mongodb. field store 1 or 0 in database, shown text. if mongo has value 1 "the value in mongo 1" , when field has value of 0 "the value zero". (just example, other texts, illustrate want)

i post controller, html , current output. 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, see in html. change value of "aanwezig" in case value of aanwezig 0 or 1. can calcultation of things or put string based on value.

firstname1 1 firstname2 0 

something else, great learn, how can specific mongodb query push of button , result.

you can create custom filter :

.filter('formataanwezig ', function() {   return function(aanwezig ) {   switch(aanwezig ) {     case 0:         return 'format0'         break;     case 1:        return 'format1'         break;     default:        return aanwezig  }    } }) 

and in html

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

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -