angularjs窗口未定义

时间:2015-03-02 08:56:42

标签: eclipse angularjs node.js express

每次我尝试在eclipse IDE中运行我的Node Express项目时都会出现以下错误,我在Eclipse中使用npm安装了角度但它给了我这个错误

这是我到目前为止所做的:

Angularapp.html

<!doctype html>
<html ng-app = "AngularApp">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<title>Login</title>
</head>
<body>
    <h1>Login</h1>
    <h2>Welcome!</h2>
    <div ng-controller="AngularController">
        Username: <input type="text" ng-model="usrname" value="1" /> <br />
        Password: <input type="text" ng-model="password" value="2" /> <br />
        <div>
            <br />
            <button type="button" ng-model="login" ng-click="signIn()">Login</button>
        </div>

        <script src="./routes/AngularApp.js"></script>
    </div>
</body>
</html>

AngularApp.js

var usrname, paswd;
var AngularApp = angular.module('AngularApp', []);

function AngularController($scope, $http, $location, $window) {
    $scope.signIn = function() {
        usrname = $scope.usrname;
        paswd = $scope.password;
        var req = {
            method : 'POST',
            url : 'http://localhost:2222/login',
            data : {
                "username" : usrname,
                "password" : paswd
            }
        }

        $http(req).success(function(response) {
            //alert(JSON.stringify(response));
            if (response.login === "Success") {
                $window.location = '/successLogin/'+response.username;
                //req.url = '/successLogin/'+response.username;
            } else {
                $window.location = '/failLogin';
                //req.url = '/failLogin';
            }   
        }).error(function(error) {
            alert("Error");
        });
    };
}

AngularApp.controller('AngularController', AngularController);

app.js

/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')
  , user = require('./routes/user')
  , http = require('http')
  , path = require('path');

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', routes.index);
app.get('/users', user.list);

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});

这是错误

node_modules/angular/angular.js:26179
})(window, document);
   ^
ReferenceError: window is not defined
    at Object.<anonymous> (/Developer IDE/Projects/Node.JS/AngularTest/node_modules/angular/angular.js:26179:4)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Developer IDE/Projects/Node.JS/AngularTest/node_modules/angular/index.js:1:63)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)

有人可以帮我解决吗

0 个答案:

没有答案