2017-07-20 16 views
1

に上陸したとき、私は親スコープへの参照エラー

function parentFunction(parentService) { 
    vm.childFunction = function() { 
     parentService.funFunction() 
      .then(function(response) { /* success */ }, 
       function(response) { /* failure */ });  
    }; 
} 

私は

function(response) { /* failure */ } 

でparentServiceへのアクセス権を持っていると思った。しかし、私はparentServiceにアクセスしようとしたときに、以下のように見える角度ディレクティブを持っていますその時点で、次のエラーが表示されます。

Uncaught ReferenceError: parentService is not defined 

0123のparentServiceはどのように使用しますかセクション?

答えて

1

parentServiceはあなたのコントローラではないあなたの関数

.controller('PhotoCtrl', ['parentService', function (parentService) { 
     vm.childFunction = function() { 
     parentService.funFunction() 
      .then(function(response) { /* success */ }, 
       function(response) { /* failure */ });  
    }; 
}]) 
+0

おかげSajeetharanにパラメータとして渡す必要があります! – user123

+0

upvote助けた場合 – Sajeetharan

関連する問題