node.js - Angular JS 自动引导和手动引导模块失败

标签 node.js angularjs express

我的模块定义如下:

//controller.js
var app;

app = angular.module('toDoApp', []);

app.controller('toDoCtrl', function($scope) {
  $scope.appTitle = 'ToDo List App';
  $scope.toDoText = '';

});

我尝试通过两种方式引导我的模块,第一种是自动的:

<html ng-app ="toDoApp" ng-controller="toDoCtrl">

<script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js" </script>
<script src="controller.js" </script>
...
</html>

我尝试的第二种方法是手动引导它:

<html>

<script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js" </script>
<script src="controller.js" </script>
<script>angular.bootstrap(document, ['toDoApp']);</script>
...
</html>

我收到的错误是:[13:40:28.640] 错误:没有模块:toDoApp @ https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js:18

我试过this但这并没有解决我的问题。我还在使用 node.js 在本地服务器上运行它(我认为这不是问题......)

    // server.js
var express  = require('express');
var app = express();                        // create our app w/ express
var port = process.env.PORT || 3000;    

// config
app.configure(function() {
    app.use(express.static(__dirname + '/public'));         
});


// listen (start todoapp with server.js) 
app.listen(port, function() {
console.log("Listening on " + port);
});

最佳答案

这是一个工作版本:http://plnkr.co/edit/pIjTH94lwl6ZZv48a2Xs?p=preview

唯一的变化是确保文档已准备就绪:

<script>
   angular.element(document).ready(function() {
      angular.bootstrap(document, ['toDoApp']);
   });
<script>

docs

关于node.js - Angular JS 自动引导和手动引导模块失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20337569/

相关文章:

angularjs - 为什么单页应用程序通常必须在每个页面发出更多请求时速度更快?

javascript - ng-if 调用 ng-show?

angularjs - ionic 2 Highcharts 不可见

node.js - 输入验证、清理和服务层

node.js - 文件事件上的 Express Busboy 未触发

node.js - Strapi 开发脚本不适用于 PM2

javascript - 我应该在 Node.js 中使用哪种客户端模板?

node.js - RedisStore 忽略主机和端口字段

javascript - 当项目中不包含node_modules文件夹时,Node.js在哪里搜索模块?

Node.js。加密 cookie 与签名 cookie