Ok I asked this a few days ago without having started to code it. Now after doing some research and played around with the code I find myself a little lost.
I will explain myself better and share the code I've done so far. I am still an Angular "noob" so I hope you guys help me do this right.
I am developing an app using Mean.js which uses Angular in the client side. Mean.js creates the modules separately in diferent directories, each module has both the server and the client directories. So far I created a Customers module and an Appointments module (these being like CRUD modules)
When creating an appointment, I want to be able to select a customer from the list of customers (meaning that I have to get that data from the customers controller)
In the create appointments view, I have this typeahead component where I want to display the customers while typing their name:
<section data-ng-controller="AppointmentsController">
<input type="text" ng-model="asyncSelected" typeahead="customer for customer in findCust()" typeahead-loading="loadingCustomers" class="form-control">
</section>
Meanwhile, in the Customers module, I created a Service (this is one thing that I still don't understand pretty well) using the yeoman service generator for mean.js, which is basically a template, I just added a few things like the call to Customers.query() which was a function in the Customers client controller, a call to the Server controller to get the list of customers to be more specific:
'use strict';
angular.module('customers').factory('ShareService', [ 'Customers',
function(Customers) {
// Share service logic
// ...
// Public API
return {
listCustomers: function() {
Customers.query(); //I added this call
}
};
}
]);
Then I added the following lines of code to the Appointments controller, hoping to start getting this thing to work:
'use strict';
// Appointments controller
angular.module('appointments').controller('AppointmentsController',['$scope', '$stateParams', '$location',
'Authentication', 'Appointments','ShareService',
function($scope, $stateParams, $location, Authentication, Appointments, ShareService) {
$scope.authentication = Authentication;
/*
Appointments CRUD ops logic here
*/
// Find a list of Customers
$scope.findCust = function() {
ShareService.listCustomers();
};
}
]);
After that I went to the app, but no data is being sent, the console giving me this error when typing in the text box:
Cannot read property 'length' of undefined
So of course not getting what I expected. I know that I may have some major mistakes here. Angular has proven to be pretty easy in some things but complex in others (at least for me) and this communication between modules/controllers has gotten me stuck.
Just to clarify, I have two modules in two separate directories (Customers and Appointments), I added the ShareService to the customers module (so I was able to "share" some info). The only error I'm getting so far is the one given by the browser console. No errors in the grunt console. But this is a little messy so I know that I'm doing something wrong. What? well that's the question.
Thanks for your time.