0
を注入するとき、私はすぐに私はこれを追加して、アプリが壊れ、私は次のことを受けてきた、私のメインコントローラへrecipesApp.recipeData
と呼ばれる工場を注入しようとしていますエラー次のよう
angular.js:68 Uncaught Error: [$injector:modulerr] Failed to instantiate module recipesApp due to:
Error: [$injector:modulerr] Failed to instantiate module recipesApp.recipeData due to:
Error: [$injector:nomod] Module 'recipesApp.recipeData' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
私の主なアプリケーションモジュールが書かれている:
var app = angular.module('recipesApp', ['ngRoute', 'recipesApp.recipeData']);
マイコントローラ:
app.controller('MainController', ['$scope', '$http', '$location', '$rootScope', 'recipeData',
function($scope,$http,$location,$rootScope,recipeData) {...}]);
マイレシピ工場:
angular
.module('recipesApp.recipeData', [])
.factory('recipeData', function($http) {
return {
getAllRecipes: function(){
$http.get('/allrecipes');
}
};
});
私は、ファイル構造を変更するファイル命名規則を試してみました。私は単純に同じファイル内のコントローラ自体にリンクしようとしました、私はそれが注入されている順序を変更して、私はスペルを3倍にチェックしました。どんな提案も非常に役に立ちます!
に存在していることを確認してください
に
あなたrecipesApp.recipeData
モジュールの依存関係から、それを削除します。 $ httpという名前のモジュールはありません。 $ httpはサービスです。モジュールはサービスではなく他のモジュールに依存します。そしてあなたはcrusial情報を投稿していません.HTMLファイルは、あなたのアプリケーションのすべてのJSファイルのスクリプトタグを持っていなければなりません。 –ああ私の言葉、それは愚かな間違いでなければならないことを知っていた。 htmlファイルにscriptタグを含めるのを忘れてしまった。また、httpは実際に私のコードにはありませんでした。私はあまりにも速くそれを入力していた。私はコピーして貼り付けておくべきだった。ありがとうございました! – aadams22
@ aadams22私の答えがあなたの問題を解決する助けとなった場合は、 –