1

I am trying to use a Service (rates service) in my Controller (rates controller) and get an "Error: Unknown Provider". Does anyone have any suggestions on how to fix this? Cheers!

rates.contoller.js

(function () {
'use strict';

angular.module('print.module').controller('ratesCtrl', ['$http', '$scope', '$rootScope', 'ratesService', function ($http, $scope, $rootScope, ratesService) {
    ratesService.getRatesDataService();
}]
)})();

rates.service.js

(function () {
'use strict';

angular.module('print.module').service('ratesService', ['$scope', '$http', function ($scope, $http) {
    vm = this;

    function getRatesDataService() {
        console.log("test");
        return this.$http.get("api/Rates/GetRates");
    }

    //}
}]
)
})();

print.module.js

(function () {
"use strict";

var module = angular.module('print.module', [
    'ui.router',
]);
module.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
    $urlRouterProvider.otherwise('/print');
    $stateProvider
        .state('print', {
            url: '/print',
            templateUrl: "Public/scripts/sharedViews/printNavbar.html"

        })
        .state('print.rates', {
            url: "/rates",
            controller: 'ratesCtrl',
            templateUrl: "Public/scripts/rates/rates.view.html",
            controllerAs: 'vm'
        })

   $locationProvider.html5Mode(true);
});

}());

view (scripts tags only for reference)

<body ng-app="print.module">
<div ui-view></div>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.3.1/angular-ui-router.min.js"></script>            
    <script type="text/javascript" src="~/public/scripts/print.module.js"></script> 
    <script type="text/javascript" src="~/public/scripts/books/books.controller.js"></script>
    <script type="text/javascript" src="~/public/scripts/terms/terms.controller.js"></script>
    <script type="text/javascript" src="~/public/scripts/rates/rates.service.js"></script>
    <script type="text/javascript" src="~/public/scripts/rates/rates.controller.js"></script>
    <script type="text/javascript" src="~/public/scripts/services/modals.service.js"></script>
</body>

1 Answer 1

3

You can't use $scope inside Service

Sign up to request clarification or add additional context in comments.

2 Comments

I took it out, but unfortunately the issue remains.
I believe it's some kind of very basic question, but there is no more specific answer, because I even don't know what the name of Provider is not found. You can see this information in console right the next after the error message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.