私は AngularJS を使い始めたばかりで、いくつかの質問がありました。あなたがそれらを理解するのを手伝ってくれることを願っています。
(例として) 次のjs
フォルダー構造を持ちます。
+---admin
| | ai-constants.js
| | commons.js
| |
| +---modules
| | searcher.js
| |
constants.js
の依存関係として使用しようとしているファイルですsearcher.js
。その内容は次のとおりです。
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,
}
});
そして、これがコンテンツの一部です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;
});
js
動作するかどうかをテストするために、ファイルを読み込んでみました:
<script type="text/javascript" src="js/admin/ai-constants.js"></script>
<script type="text/javascript" src="js/admin/modules/searcher.js"></script>
しかし、いけません!だから私は疑問に思っていました:
- 私はそれを正しくやっていますか?
- パスからファイルを依存関係としてロードする方法はあり
js
ますか (ほとんどの場合、リテラル オブジェクトが含まれます)。
アップデート
私が得るエラーは次のとおりです。
キャッチされていないエラー: モジュールがありません: tagCategory