2016-07-20 5 views
0

私のangularJSアプリケーションでは、以下のように私のアプリケーションを設定しました。私はモジュールを定義して、私のすべてのファクトリメソッドを定義しました。別のファイルで AngularJS Appの不明なサービスプロバイダ

angular.module("services", []); 
var app = angular 
    .module('myApp', [ 
    'services' 
    ]); 

は、私が サービスモジュールに工場を定義しているが、私はアプリを実行したときに、私は次のエラーを取得:私はstackoverflowの中の記事の多くを確認し

Unknown provider: myServicesProvider <- myServices <- myCtrl

angular.module('services').factory('myServices', function ($http) { 
    return { 
    createPet(pet) { 
     return $http.post('/pets', pet); 
    } 

    }; 
}); 

angular.module('myApp') 
    .controller('myCtrl', myServices) { 

    }); 

を私は正しい方法で定義を行ったと思います。誰でも手掛かりがありますか?あなたの工場で括弧を置き忘れてきた

答えて

0

は、ここで作業コードです:それはコピー&ペーストのタイプミスだった

angular.module("services", []); 
var app = angular 
    .module('myApp', [ 
    'services' 
    ]); 

app.controller('mainController', function($scope, myServices){ 
    $scope.items = myServices.query(); 
    $scope.bill = {}; 
    $scope.totalBeforeDiscount = {}; 
    $scope.totalPrice = function(){ 
     var total = 0; 
     for (var i = 0; i <= $scope.items.length - 1; i++) { 
      total += $scope.items[i].price * $scope.items[i].quantity; 
     } 
     $scope.totalBeforeDiscount =total; 
    } 
}) 

angular.module('services').factory('myServices', function ($http) { 
var items = {}; 
    return { 
    query: function() { 
     return [{ 
     title: 'Paint pots', 
     quantity: 8, 
     price: 3.95 
     }, { 
     title: 'Polka dots', 
     quantity: 17, 
     price: 12.95 
     }, { 
     title: 'Pebbles', 
     quantity: 5, 
     price: 6.95 
     }]; 
    } 
    }  

}); 

ワーキングApplication

+0

申し訳ありません。私は詳細をつけて質問を更新しました。私はまた、そのサービスを使用するコントローラを持って、私は上記の他のエラーを取得します。 – sansari

+1

@sansari plunkerアプリケーションをチェックすると、 – Sajeetharan

+0

ありがとうございます。私は、index.htmlにmyService.jsを追加していないことを知りました!プロジェクトが大きくなると、jsファイルが増えます。どのようにhtml.indexに追加しなくてもそれらを管理できますか?もう一度ありがとう – sansari

関連する問題