I just got started with AngularJS, and I just got a couple of questions that hopefully you can help me figure them out.
Having (as an example) the following js
folder structure:
+---admin
| | ai-constants.js
| | commons.js
| |
| +---modules
| | searcher.js
| |
constants.js
is that a file that I'm trying to use it as a dependency in searcher.js
, and here is its content:
var aiConstants = angular.module("aiConstants", []);
aiConstants.factory("user", function () {
return {
ahaha: 0,
}
});
aiConstants.factory("tagCategory", function () {
return {
none: 0,
artisticMovement: 1,
technicalMaterials: 2,
art: 3,
organizations: 4,
professionals: 5,
}
});
And here's the some of the content of searcher.js
var app = angular.module('searcher', ['tagCategory']);
app.controller('SearcherController', function($scope, $http) {
$http.get('/api/search/tags/'+tagCategory.art).success(function(data) {
$scope.tiposDeArte = data;
});
To test if it works, I tried loading the js
files:
<script type="text/javascript" src="js/admin/ai-constants.js"></script>
<script type="text/javascript" src="js/admin/modules/searcher.js"></script>
But, no go! So I was wondering:
js
file as dependency (mostly will contain literal objects) from a path?The error I get is:
Uncaught Error: No module: tagCategory
Your searcher
module needs a dependency defined for the aiConstants
module. Then you can inject services from that module where you need to. So, it would look something like this:
var app = angular.module('searcher', ['aiConstants']);
app.controller('SearcherController', function($scope, $http, tagCategory) {
$http.get('/api/search/tags/'+tagCategory.art).success(function(data) {
$scope.tiposDeArte = data;
});