Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 从控制器中的不同文件注册服务_Angularjs - Fatal编程技术网

Angularjs 从控制器中的不同文件注册服务

Angularjs 从控制器中的不同文件注册服务,angularjs,Angularjs,我无法从控制器中的一个文件在另一个文件中注册服务 我有一个名为“script.js”的主文件,它看起来像这样: (function() { var app = angular.module("myApp", []); var MainController = function(scope, github, interval, log, anchorScroll, location) { //some code which is not important here };

我无法从控制器中的一个文件在另一个文件中注册服务

我有一个名为
“script.js”
的主文件,它看起来像这样:

(function() {
  var app = angular.module("myApp", []);

  var MainController = function(scope, github, interval, log, anchorScroll, location) {
      //some code which is not important here
  };

  app.controller("MainController", ["$scope", github, "$interval", "$log", "$anchorScroll", "$location", MainController]);
}());
还有第二个文件名为“
”github.js”

它不起作用了。。。我不知道我错过了什么。。。我正在看教程,但它是在旧版本的Angular上准备的

当然,在
.html
文件中,对
“script.js”
的引用在
“github.js”
之前

编辑:
我在github的依赖项中缺少了双引号,并且“github.js”-$htpp而不是$http…

代码中几乎没有拼写错误:

1.
github
依赖项必须在双引号中,
依赖项中的“github”
,如:

 app.controller("MainController", ["$scope", "github", "$interval", "$log", "$anchorScroll", "$location", MainController]); 
2.建议:在控制器中,依赖关系应该相同(缺少
$
),按如下方式操作:

 var MainController = function($scope, github, $interval, $log, $anchorScroll, $location) {

3.在工厂依赖项中,它应该是
$http
(非htpp)

您不工作是什么意思?你有什么错误吗?
github
必须在双引号中,依赖项中的
“github”
。同样在github.js中,依赖项应该是
$http
,而不是
$htpp
谢谢大家!我没有注意到这个小拼写。。。当然,github应该在dependency中使用双引号。伟大的谢谢:)顺便说一句,有人能帮我解决这个问题吗-??关于第二点。。。为什么它应该有一个美元符号??没有它它它也能工作。。。我想在那里我可以称之为任何我想…这是一个建议,它应该是一样的,。
 var MainController = function($scope, github, $interval, $log, $anchorScroll, $location) {