我有一个Angular指令,如下所示
function parentFunction(parentService) {
vm.childFunction = function() {
parentService.funFunction()
.then(function(response) { /* success */ },
function(response) { /* failure */ });
};
}
我想在
访问parentServicefunction(response) { /* failure */ }
但是当我在那时尝试访问parentService时,它会给我以下错误:
Uncaught ReferenceError: parentService is not defined
如何在function(response) { /* failure */ }
部分使用parentService?
答案 0 :(得分:1)
parentService
应作为参数传递给您的控制器而不是您的功能
.controller('PhotoCtrl', ['parentService', function (parentService) {
vm.childFunction = function() {
parentService.funFunction()
.then(function(response) { /* success */ },
function(response) { /* failure */ });
};
}])