错误:参数不是一个函数,得到了不确定 [英] Error: Argument is not a function, got undefined

查看:223
本文介绍了错误:参数不是一个函数,得到了不确定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用AngularJS使用Scala玩,我得到这个错误。


  

错误:参数'MainCtrl不是一个函数,得到了不确定


我试图创建一个包含的星期几的表。

请看看我的code。我已经检查了控制器的名称,但似乎是正确的。注意:从这个SO 答案使用code

index.scala.html

  @(消息:字符串)@main(银泰){<!DOCTYPE HTML>
< HTML LANG =ENNG-应用>
    < HEAD>
        <链接rel =stylesheet属性的媒体=屏幕上的href =@ routes.Assets.at(样式表/的main.css)>
    < /头>
< D​​IV NG控制器=MainCtrl>
    <表边框=1>
    < TBODY NG重复='(什么,物品)在数据'>
      < TR NG重复=项中的项目'>
        < TD NGM-IF =$第一行跨度={{items.length}}> {{}什么}< / TD>
        < TD> {{}项}< / TD>
      < / TR>
    < / TBODY>
  < /表>
< / DIV>
< / HTML>
}

MainCtrl.js

 (函数(){
    angular.module('[对myApp]',[])。控制器('MainCtrl',函数($范围){
        $ scope.data = {
            颜色:星期一,星期二,星期三,星期四,星期五]
        }
    });
}());


解决方案

删除 [] 从名字([对myApp])模块

  angular.module('对myApp',[])

和增加 NG-应用=对myApp来的HTML,它应该工作。

Using AngularJS with Scala Play, I'm getting this error.

Error: Argument 'MainCtrl' is not a function, got undefined

I'm trying to create a table consisting of the days of the week.

Please take a look at my code. I had checked the name of the Controller, but that seems correct. Note: Code used from this SO answer

index.scala.html

@(message: String)

@main("inTime") {

<!doctype html>
<html lang="en" ng-app>
    <head>
        <link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
    </head>
<div ng-controller="MainCtrl">
    <table border="1">
    <tbody ng-repeat='(what,items) in data'>
      <tr ng-repeat='item in items'>
        <td ngm-if="$first" rowspan="{{items.length}}">{{what}}</td>
        <td>{{item}}</td>
      </tr>
    </tbody>
  </table>
</div>
</html> 
}

MainCtrl.js

(function() {
    angular.module('[myApp]', []).controller('MainCtrl', function($scope) {
        $scope.data = {
            Colors: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
        }
    });
}());

解决方案

Remove the [] from the name ([myApp]) of module

angular.module('myApp', [])

And add ng-app="myApp" to the html and it should work.

这篇关于错误:参数不是一个函数,得到了不确定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆