2015-10-08 57 views
0

我得到上述角度的错误,我不知道是什么问题。参数'DemoController'是不是一个函数,得到了undefined

我正在使用路由器来调用模板和相关的JS文件。

这里是我的路由器代码:

...

$router.config([ 

      { 
       path:'/preview', 
       component: 'connections/preview' 
      } 
      ]); 

... 我的模板文件具有相同的名称和所使用的控制器如下:

...

<div ng-controller="PreviewController as prevCtrl"> 

...

而JS文件如下。

...

(function(){ 
    'use strict'; 
    angular.module('myMod',[]).controller('PreviewController', function($http){ 

var vm = this; 

     $http.get("https://api.myjson.com/bins/30e2a") 
      .success(function(response) { 
      //Dummy data taken from JSON file 
      vm.firstName = response.firstName; 
      vm.lastName = response.lastName; 
      vm.dateAdded = response.dateAdded; 
      vm.typeofDB = response.typeofDB; 
      vm.accessLevel= response.accessLevel; 
      vm.description = response.fileDescription; 
      vm.fileSize = response.fileSize; 
      vm.columns = response.columns; 
      vm.rows = response.rows; 
      vm.demoFileName = response.fileName; 
      vm.demoFileType = response.fileType; 
      vm.usersName = response.usersName; 


}; 

...

当我加载页面时,我收到以下错误:

错误:[NG:AREQ]参数 'PreviewController'是不是一个函数,得到undefined

我想我的角脚本没有得到加载。

有人可以指导我,我要去哪里错了吗?

回答

0

您可能已经在别处定义了您的模块。在上面的代码中,方括号重新定义它。所以,如果你没有在其他地方定义它,只是改变:

angular.module('myMod',[]).controller('PreviewController', function($http){ 

要:

angular.module('myMod').controller('PreviewController', function($http){ 

,你应该是好去。

+0

我试图删除方括号,但我仍然得到相同的错误... –

+0

你的语法一切都很好。这将是一件愚蠢的事情,就像不加载JavaScript文件或类似的东西。如果你找不到它,Codepen或Plunkr可能是必要的。 –

相关问题