0

https://i.sstatic.net/u8QL3.jpg is a picture of my error.

dicym.js

var app = angular.module('diycm', ['ngRoute', 'LocalStorageModule']);

// setup the routing
app.config(function ($routeProvider) {

    $routeProvider
    .when('/home', {
        templateUrl: 'views/home.html',
        controller: 'homeController',
        title: 'Home'
    })
    .when('/projects', {
        templateUrl: 'views/projects.html',
        controller: 'homeController',
        title: 'Projects'
    })
    .when('/singleProject', {
        templateUrl: 'views/singleProject.html',
        controller: 'homeController',
        title: 'Project Details'
    });

    $routeProvider.otherwise({ redirectTo: "/home" });

});

// Controls the rootscope
app.run(function ($rootScope, $route) {
    $rootScope.$on("$routeChangeSuccess", function (currentRoute, previousRoute) {
        //Change page title, based on Route information
        $rootScope.title = $route.current.title;
    });
});

homeController.js

app.controller('homeController', function ($scope, $http) {
    $scope.message = 'Everyone come and look!';
});

sidebarController.js

app.controller('sidebarController', function ($scope, $location) {
    $scope.isActive = function (viewLocation) {
        return viewLocation === $location.path();
    };
});

index.html

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.2/angular.min.js" type="text/javascript"></script>
<script src="https://code.angularjs.org/1.4.5/angular-route.js" type="text/javascript"></script>
<script src="js/diycm.js"></script>
<script src="js/angular-local-storage.min.js"></script>
<script src="js/controllers/sidebarController.js"></script>
<script src="js/controllers/homeController.js"></script>

Does anyone have any idea what could be causing this error? New to angular and the documentation / past questions haven't been much help.

1
  • 1
    You are not injecting the dependencies in your controller. You should inject the dependencies and then run the code again. Commented Mar 27, 2016 at 6:21

1 Answer 1

2

Inject dependencies for each controller.

1)

app.controller('homeController', ['$scope','$http',function ($scope, $http) {
    $scope.message = 'Everyone come and look!';
}]);

and

app.controller('sidebarController',['$scope','$location',function ($scope, $location) {
    $scope.isActive = function (viewLocation) {
       return viewLocation === $location.path();
    };
}]);

2)

app.controller('homeController',homeController); 
homeController.$inject = ['$scope','$http'];
function homeController($scope, $http) {
    $scope.message = 'Everyone come and look!';
}]);

and

app.controller('sidebarController',sidebarController);
sidebarController.$inject = ['$scope','$location'];
function sidebarController($scope, $location) {
    $scope.isActive = function (viewLocation) {
       return viewLocation === $location.path();
    };
}]);
Sign up to request clarification or add additional context in comments.

Comments

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.