2016-10-01 10 views
0

enter image description here angularjsの新機能です。 frontendServicedd < - - CustSignupCtrlコントローラへの注入サービスは動作しません。

service.js

frontendServiceddProvider <:12520エラー:[$インジェクター:UNPR]不明なプロバイダ私は、データが、エラー

angular.js以下の投げを投稿する角度のサービスを使用しようとしています私は両方のJSファイルの参照を与えている

app.service('frontendService', function frontendService ($http, $q, $rootScope){ 

     var list = this; 


     list.registerCust = function(data){ 
      var defer = $q.defer(); 

      $http({ 
       url: $rootScope.endPoint, 
       method: "POST", 
       data: data 
      }) 
      .success(function(res){ 
       console.log("Successfull!"); 
       defer.resolve(res); 
      }) 
      .error(function(err, status){ 
       console.log("Failed !"); 
      }) 

      return defer.promise; 
     } 

     return list; 

    }); 

customer_signup.js

app.controller('CustSignupCtrl', ['$scope', '$filter','frontendService', '$http', 'editableOptions', 'editableThemes','notify','notification','$appConstants', 
    function('$scope', '$filter','frontendService', '$http','editableOptions', 'editableThemes','notify','notification','$appConstants'){ 


    $scope.pw1 = ''; 

    $scope.registerCustomer = function (data) { 
     return frontendService.registerCust(data) 
    } 

    $scope.signupcustomer = function(){ 

     var payload= { 
     first_name: $scope.custForm.fname, 
     last_name: $scope.custForm.lname, 
     phone: $scope.custForm.phone, 
     email:$scope.custForm.email, 
     username:$scope.custForm.username, 
     password:$scope.custForm.pw1, 
     usertype:3 
     } 
     console.log("inside function"); 
     $scope.registerCustomer(payload).then(function(data){ 
     notification.success(data.result); 
     },function(err){ 
     notification.error("Error: contact system admin"); 
     }); 

    } 
    } 
]) 

index.htmlの中で..間違ってやっているところ得ていない...誰もがあなたがinjectコントローラに、同じ順序である必要がありますどのような

+0

あなたの注射は適切ではありません。変数は、 '$ scope'、 'frontendService'、 '$ filter'、 '$ http'、 'editableOptions'、 'editableThemes'、 'notify'、 'notification'、 '$ appConstants'に似ています。 あなたの関数のパラメータはコントローラ関数内で同じ順序でなければなりません –

答えて

2
app.controller('CustSignupCtrl', ['$scope', '$filter', 'frontendService', '$http', 'editableOptions', 'editableThemes','notify','notification','$appConstants', 
    function($scope, $filter, frontendService, $http, editableOptions, editableThemes, notify, notification, $appConstants){ 

    $scope.pw1 = ''; 
}); 

を助けることができます。 functionの注射用品の引用符を削除します。

+0

返信ありがとうございます.. 2つのエラーを取得できません1)customer_signup.js:2 Uncaught SyntaxError:予期しない文字列2)angular.js:12520 Error:[ng:areq ]引数 'CustSignupCtrl'が関数ではない、定義されていません – Raghav

+0

ブラウザコンソールのスクリーンショットで質問を更新できますか?そこにいくつかのエラーがあるはずです。 –

+0

よろしくお願いします。更新しました。 – Raghav

2

これはのように言って、問題の依存性注入の不一致ソートそれは[]

内にそれらを見ていると、あなたのjsファイル内の関数を宣言した場合注入は、例えば、関数にオブジェクト

AngularJSすることができあなたがコンソールに入るものとする。この

var app = angular.module('app',[]); 
app.controller('maincntrl',function($scope){ 

}); 
var search = function($scope,searchtext,searchfilters,searchareas) 
{ 
    return 'result' 
} 

console.log(angular.injector.annotate(search)); 

結果は次のようになります

["$scope","searchtext","searchfilters","searchareas"] 

AngularJSそれはそれは"$scope"を見て、各配列要素とモーメントを通過配列

として関数のパラメータを解析し、それが今、その位置

にスコープobjectを注入し、あなたが使用している構文基本的にminification

だからあなたの宣言に従って

のために使用されています

あなたは依存性の注入が起こっされていない場合にはstringsとしてfunctionパラメータを宣言しているので、そう

$scope--> shall be injected into $scope 
frontendService-->shall be injected into $filter 
$filter--> shall be injected into frontendService 
. 
. 
. 
so on 

はまた、(あなたがコメントで述べた)エラーが発生しています。これらの問題を解決することで、あなたの問題は解決されます。

関連する問題