在我的 AngularJS node.js 中app https://github.com/zishe/angular-express-coffee基于角度表达博客 https://github.com/btford/angular-express-blog and 速溶咖啡 https://github.com/twilson63/express-coffee我对定义有疑问angular.module
在控制器之前pic http://clip2net.com/s/2bkYH:
Uncaught ReferenceError: IndexCtrl is not defined
包含模块的顺序与 Angular-seed 中的相同:
// JS
!= js('lib/jquery-1.7.2.min.js')
!= js('lib/bootstrap.min.js')
!= js('lib/angular.min.js')
!= js('app')
!= js('controllers')
!= js('directives')
!= js('filters')
!= js('services')
更改顺序后:
!= js('controllers')
!= js('app')
!= js('directives')
!= js('filters')
!= js('services')
错误一样。仅当我之前将控制器替换为 app.coffee 时才有效angular.module("myApp"...
定义。我当然重新启动了服务器。
Update: app file https://github.com/zishe/angular-express-coffee/blob/master/assets/js/app.coffee, 控制器文件 https://github.com/zishe/angular-express-coffee/blob/master/assets/js/controllers.coffee and layout https://github.com/zishe/angular-express-coffee/blob/master/views/layout.jade
在 Coffeescript 中,编译好的东西被包装在一个闭包中:
//controllers.js:
(function() { function MyController($scope) {} })();
现在index.html找不到MyController变量,因为它在闭包中!
Use the module.controller
语法代替。
angular.module('myApp').controller 'MyController', ($scope) ->
这将使您的控制器在任何地方都可见。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)