我是AngularJS的新手,我正在学习工厂/服务。我将这个简单的应用程序编码为在Controller中传递Fire Factory,但是当我在控制器中注入Factory / Service时会抛出错误
home.html的
<div class="home" ng-controller="HomeCtrl">
Home <button ng-class="logut()">LogOut</button>
{{test}}
</div>
app.js
cheers.factory('Fire',function($scope,$location,$firebaseObject){
return {name : 'Pawan Choudhary'};
});
cheers.controller('HomeCtrl', ['$scope','$location','Fire',function ($scope, $location,Fire) {
$scope.test = "working!";
}]);
它会抛出以下错误:
答案 0 :(得分:1)
确定!谢谢大家,我通过从工厂中移除$ scope来修复错误。
答案 1 :(得分:0)
工厂的标题不正确,如果要添加$ scope,它必须看起来像您的控制器标题。试试这个:
cheers.factory('Fire',['$scope', '$location', '$firebaseObject', function($scope,$location,$firebaseObject){
//your code
}]);