代码在角度上没有按预期工作

时间:2021-10-29 02:17:13

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.

这段代码不断给我一个错误,说明:'videoControllers.videoControllers不是一个函数'。我正在使用的教程是以这种方式编写的,它正在工作,但我的项目给了我这个错误。谁能请帮忙。

2 个解决方案

#1


3  

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

在使用videoControllers时,关键字是控制器。更改您的代码如下:

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;
        });

});

#2


1  

Try this coz in ur code ur not accessing controller

在你的代码中尝试这个coz你不访问控制器

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;
            });
});

#1


3  

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

在使用videoControllers时,关键字是控制器。更改您的代码如下:

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;
        });

});

#2


1  

Try this coz in ur code ur not accessing controller

在你的代码中尝试这个coz你不访问控制器

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;
            });
});