[英]'angular' is not defined in javascript file of Node Express Project in Eclipse
I wanna use Angular.js as my front end in Node Express Project creating in Eclipse IDE. 我想将Angular.js用作在Eclipse IDE中创建的Node Express Project的前端。 Whenever I try to move my angular controller in separate js file i get 'angular' is not defined
, also in html file Cannot find module with name AngularApp.
每当我尝试在单独的js文件中移动我的角度控制器时,我'angular' is not defined
,也在html文件中Cannot find module with name AngularApp.
are errors that I'm receiving. 是我收到的错误。
How do I use angular script code in different javascript file in a Node Express Project in Eclipse IDE? 如何在Eclipse IDE的Node Express项目中的不同javascript文件中使用角度脚本代码?
Here is what I have so far: 这是我到目前为止的内容:
Angularapp.html 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 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 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'));
});
Your problem is that you are trying to get anugular app which you have not defined yet, You need to define it first. 您的问题是您正在尝试获取尚未定义的应用程序,您需要先定义它。
To define use 定义用途
var AngularApp = angular.module('AngularApp', []);
To get already defined app use 要获取已定义的应用程序使用
var AngularApp = angular.module('AngularApp');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.