0

私は 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>

しかし、いけません!だから私は疑問に思っていました:

  1. 私はそれを正しくやっていますか?
  2. パスからファイルを依存関係としてロードする方法はありjsますか (ほとんどの場合、リテラル オブジェクトが含まれます)。

アップデート

私が得るエラーは次のとおりです。

キャッチされていないエラー: モジュールがありません: tagCategory

4

1 に答える 1