Tatenda
Tatenda

Reputation: 699

code not working as intended in angular

I have the following code set up:

var videoControllers = angular.module('videoControllers', []);

videoControllers.videoControllers('VideoDetailController', function($scope, $routeParams, $http){
    $http.get('http://localhost:8000/videos/api/video/' + $routeParams.videoId + '/?format=json').success(
            function(data){
                $scope.video = data;
            });
})

This code keeps giving me an error which state that: 'videoControllers.videoControllers is not a function'. The tutorial I am using is written in that manner and it is working, but my project gives me this error. Can anyone please help.

Upvotes: 0

Views: 46

Answers (2)

Atul Chaudhary
Atul Chaudhary

Reputation: 3736

Try this coz in ur code ur not accessing controller

angular.module('videoControllers').controller('VideoDetailController', function($scope, $routeParams, $http){
    $http.get('http://localhost:8000/videos/api/video/' + $routeParams.videoId + '/?format=json').success(
            function(data){
                $scope.video = data;
            });
});

Upvotes: 1

Aditya Singh
Aditya Singh

Reputation: 16660

Becuase the keyword is controller while you are using videoControllers. Change your code as below:

var videoControllers = angular.module('videoControllers', []);

videoControllers.controller('VideoDetailController', function($scope,  $routeParams, $http){
      $http.get('http://localhost:8000/videos/api/video/' +     $routeParams.videoId + '/?format=json')
       .success(function(data){
            $scope.video = data;
        });

});

Upvotes: 3

Related Questions