javascript - Mean.js Stack - export.read with findOne and find functions, call in Angularjs -


i new mean.js, , little confused on how use export.read , call findone function find function added in. have customers module , customer-users module in app. have customers.server.controller, customer-users.server.controller, , client controllers. customer organization. , there users fall under customer. can display customer-users list export.list in customer-users module. can display list of customers in customers module, , of course have customer view when select customer. want when select customer, list of customer-users display underneath customer name on customer view. have tried edit customers.server , customers.client controllers done, unsure of right way go this.

here customers.server.controller.js:

'use strict'; /** * module dependencies. */ var mongoose = require('mongoose'), errorhandler = require('./errors.server.controller'), customer = mongoose.model('customer'), passport = require('passport'), user = mongoose.model('user'), customeruser = mongoose.model('customeruser'), _ = require('lodash');  /** * show current customer */ exports.read = function(req, res) {     customer.findone({ _id: req.params.customerid }).exec(function(err, customer) {         if (err) {             return res.status(400).send({                 message: errorhandler.geterrormessage(err)             });         } else {             customeruser.find({ customer: req.customer }).sort('-created').exec(function(err, customerusers) {                 if (err) {                     console.log('error');                     return res.status(400).send({                         message: errorhandler.geterrormessage(err)                     });                 } else {                     var customeruserslist = customerusers;                     var selectedcustomer = customer;                     var customerwithusers = {                         customer: selectedcustomer,                         customerusers: customeruserslist                     };                     console.log('1 : ' + customeruserslist);                     console.log('2 : ' + selectedcustomer);                     console.log('3 : ' + customerwithusers);                     res.jsonp(customerwithusers);                 }             });         }     }); }; 

i have been trying debug code console.log calls, , seems giving me proper arrays looking for. feel should work on server side.

my customers.client.controller.js (so far; confused how correctly this):

use strict';  // customers controller angular.module('customers').controller('customerscontroller', ['$scope', '$stateparams', '$location', 'authentication', 'customers', 'admincustomerusers', 'customerusers', function($scope, $stateparams, $location, authentication, customers, admincustomerusers, customerusers) {     $scope.authentication = authentication;     $scope.customerid = $stateparams.customerid;      $scope.findone = function() {         $scope.customer = customers.get({             customerid: $stateparams.customerid         });          $scope.customerusers = customers.query({             customer: $scope.customer         });         console.log($scope.customer);         console.log($scope.customer.customerusers);         console.log($scope.customerusers);     }; 

i have tried many different things, not extent of had, base findone call individual customer.

my view-customers.client.view.html (which of course have revised upon working solution):

 <section data-ng-controller="customerscontroller" data-ng-init="findone()">     <div class="page-header">         <h1 data-ng-bind="customer.name"></h1>     </div>      <div class="pull-right" data-ng-show="((authentication.user) && (authentication.user._id == customer.user._id))">         <a class="btn btn-primary" href="/#!/customers/{{customer._id}}/edit">             <i class="glyphicon glyphicon-edit"></i>         </a>         <a class="btn btn-primary" href="/#!/customer-users/{{customer._id}}/create">             <i class="glyphicon glyphicon-user"></i>             <i class="glyphicon glyphicon-plus"></i>         </a>         <!-- <a class="btn btn-default btn-danger" data-ng-click="remove();">             <i class="glyphicon glyphicon-trash"></i>         </a> -->     </div>     <small>         <em class="text-muted">             added on             <span data-ng-bind="customer.created | date:'mediumdate'"></span>                         <span data-ng-bind="customer.user.displayname"></span>         </em>     </small>      <br /><br /><br />     <div class="list-group">         <div data-ng-repeat="customeruser in customerusers" class="list-group-item">             <h4 class="list-group-item-heading">                 {{customeruser.user.displayname}}                 hello                 <small class="label label-default" ng-show="customeruser.admin">admin</small>             </h4>         </div>     </div> </section> 

so question how customer-users list under customer view? going wrong? there better way? said, seems work on server side, can't call customerusers array populated correct object on client side. there way use customeruserscontroller in view alongside customerscontroller can use customer-users controller make happen? because tried doing , failed miserably. missing logic here. in advance help.

is there code calls server (node.js / customers.server.controller.js) client?

since call asynchronous, customers.get() , customers.query() functions should returning promises. angular not automatically unwrap those.

something should work:

customers     .get({         customerid: $stateparams.customerid     })     .then(function(customer){         $scope.customer = customer;     }); 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -