As someone new to web development and Angular, I recently created a module, factory, and controller all in the same file (app.js). Below is an example of the code:
//Main Module
var ipCharts = angular.module('ipCharts', []);
//Factory
ipCharts.factory('securityFactory', function ($http) {
var securities = {};
$http.get('api/Securities').
success(function (data, status, headers, config) {
securities = data;
}).
error(function (data, status, headers, config) {
// log error
});
var factory = {};
factory.getSecurities = function () {
return securities;
}
return factory;
});
//Controller
ipCharts.controller('securityController', function ($scope,securityFactory) {
$scope.securities = securityFactory.getSecurities();
});
I'm currently exploring how I can separate the module, factory, and controller into different files.
I have successfully placed the controller in a separate file if it doesn't reference the factory. However, I'm facing issues when the controller uses the factory while the factory is in a separate file. Any tips or insights would be greatly appreciated!