node.js - 找不到 AngularJS Express 咖啡 Assets Controller

标签 node.js coffeescript express angularjs

在我的 AngularJS node.js 中 app基于 angular-express-blogexpress-coffee我在 Controller pic 之前的防御 angular.module 有问题:

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')

错误相同。只有当我在 angular.module("myApp"... defenition 之前将 Controller 替换为 app.coffee 时,它​​才有效。我当然重新启动了服务器。

更新:app file , controller filelayout

最佳答案

在 Coffeescript 中,编译后的东西被包裹在一个闭包中:

//controllers.js:
(function() { function MyController($scope) {} })();

现在 index.html 找不到 MyController 变量,因为它在闭包中!

改用 module.controller 语法。

angular.module('myApp').controller 'MyController', ($scope) ->

这将使您的 Controller 随处可见。

关于node.js - 找不到 AngularJS Express 咖啡 Assets Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11830370/

相关文章:

javascript - 使用带有 Meteor 的 Cordova 文件插件,收到代码 : 5 ENCODING_ERROR in getDirectory() callback

javascript - 从 NodeJS 发送数据而不重新渲染整个页面?

javascript - 在 node.js 中使用 sharp 压缩图像

node.js - 如何在mongodb聚合中将动态值传递给$in

javascript - 没有 babel 或 webpack 的 ReactJS Hello World

node.js - 尝试使用 Mongoose 从另一个字段的查找中返回 1 个字段

node.js - 使用 mongoose,express 搜索短语

javascript - 如何将 HTTP 请求映射或关联到 Node.js 中的数据库调用?

javascript - 如何使用 jQuery 选择这个子 div 元素来显示/隐藏?

javascript - 从 crypto.randomBytes 中排除某些字符的正确方法