Brian Kelleher Brian Kelleher - 17 days ago 7
AngularJS Question

Why am I getting $injector:unpr (unknown provider) in this single page app?

Writing a single page angular app, but I am getting the Injector Error (unknown provider). Do I have to do more to make angular aware of my controller?

HTML:

<div ng-app="AvailablePets" ng-controller="homeController">
{{pets}}
</div>


JS:

var app = angular.module('AvailablePets', [])
.controller('homeController', function( $scope ) {
console.log('App Home Controller');
// Controller Logic
$scope.pet = "Dog";
});

Answer

Use Inline Array Annotation to inject the dependency in angular

Change to this

 var app = angular.module('AvailablePets', [])
      .controller('homeController',['$scope', function( $scope ) {
        console.log('App Home Controller');
        // Controller Logic
        $scope.pet = "Dog";
    }]);
Comments