javascript - AngularJS Service Undefined: Unknown provider: $scopeProvider <- $scope -
i've started learning angular js , i'm having problem injecting service controller. i'm trying put threadfactory
service threadcontroller
, i'm getting undefined error when calling it. advice great. error i'm getting is:
unknown provider: $scopeprovider <- $scope <- threadservice
app.js
angular.module('threadsapp', ['ngroute']); angular.module('threadsapp') .config(function ($routeprovider, $locationprovider) { $routeprovider .when('/', { templateurl: 'views/index.html', }) .when('/selected/:topicname', { templateurl: 'views/threads.html', controller: 'threadcontroller', }) .otherwise({ redirectto: "/" }); $locationprovider.html5mode(true); });
threadcontroller.js
angular.module('threadsapp').controller("threadcontroller", ["$scope", "$route", "$routeparams", "threadservice", function ($scope, $route, $routeparams, threadservice) { $scope.test = "hello!"; $scope.test2 = threadservice.get(); }]);
threadservice.js
angular.module('threadsapp').service("threadservice", ["$scope", function ($scope) { return { get: function() { return "hello"; } } }]);
order of imports
<script src="bower_components/jquery/dist/jquery.js"></script> <script src="bower_components/angular/angular.js"></script> <script src="bower_components/angular-route/angular-route.js"></script> <script src="bower_components/bootstrap/dist/js/bootstrap.js"></script> <script src="components/app.js"></script> <script src="components/bodycontroller.js"></script> <script src="components/topiccontroller.js"></script> <script src="components/threadservice.js"></script> <script src="components/threadcontroller.js"></script>
you can't inject $scope
threadservice
way you're trying to. $scope
isn't typical service when inject controller. if remove $scope
injection threadservice.js, bet error go away.
in interest of not being redundant, fuller explanation can found here:
Comments
Post a Comment