D
D
Deodatuss2015-06-11 12:55:50
Angular
Deodatuss, 2015-06-11 12:55:50

Why is the run method throwing an error?

Here is the actual code:

angular.module('user').run(
    function($scope,Authentication,$routeParams,$location){
        $scope.username =$routeParams.userName;
        $scope.currentUserPageSection = $routeParams.section;
        Authentication.getUser($scope.username,function(data){
            if(data.username){
                $scope.pageUser = data;
                var status = $scope.user._id === $scope.pageUser._id;
                $scope.itsMyPage = status;
                $scope.$parent.$parent.itsMyPage = status;

            } else {
                $location.path('/');
            }
        },function(){
            $location.path('/');
        });
    });

and here is the error:
Uncaught Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope
errors.angularjs.org/1.4.0/$injector/unpr?p0=%24sc...

I feel business is covered in my misunderstanding of DI. I'll be grateful for the advice

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Protko, 2015-06-11
Protko @Fesor

Let's make life a little better. Just forget about scopes. The only place to inject them is in the link function of the directive. nowhere else is it really needed. Not in controllers (use controller as syntax), not in services (you can inject $rootScope for events and only) or anywhere else. Well, yes, you can shove $rootScope into run to set some global things, although again it’s better to just make an ApplicationController.

V
Valentin Dubrovsky, 2015-06-11
@matroskin13

$scope - not available in run.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question