Saturday, 8 April 2017

node.js with mongodb and angularjs data binding

I'm trying to receive data from node.js with angularjs.

without angularjs, I can handle mongodb data but with angularjs, I cannot handle it.

when alerting data received from node.js, it shows [object object].

but on jade, no data showing now.

app.get and angularjs works fine but no data binding.

any ideas for me?

thank you for reading!

app.js

app.get('/studentlist', (req, res) => {    
    dbs.collection('slist').find({}).toArray((err, result) => {
        if (err) return console.log(err)
        //res.send(JSON.stringify(result));  
        var data = JSON.stringify(result);
        //console.log(data);
        res.send({ result: data });
        console.log('data sent');
    });   
});

angular.js code

var app = angular.module("datalist", []);
app.controller('datadisplay', function ($scope, $http) 
    var vm = this;
    vm.mydata = [];
        $http.get('/studentlist').then(function (result) {
            alert(result.data);
            $scope.slist = result.data;
        })

});

jade code

extends layout

block content
    h1 Student list    
    label Search:
        input(ng-model="searchText")
    .studentlist 
        table.table
            thead
                tr
                    th Name
                    th Age
                    th Class                    
            tbody(ng-app="datalist")             
                    tr(ng-controller="datadisplay" ng-repeat"mongo_result in slist | filter:searchText")
                        form(action='/detail', method="POST" class="slist")
                            th
                                
                            th
                                
                            th
                                
                            th
                                button.btn-primary(type="submit") Detail
                            th 
                                button.btn-danger(type="button" class="btnOrderLiterature" data-value="" value="" ng-click="addLiteratureToSession($event)") Delete



via Chi Seong Oh

No comments:

Post a Comment