在加載我的index.html我面對這個錯誤
的index.html
<html>
<head>Testing
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js" ></script>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope,$http) {
$scope.submit= function(){
var data = {
book: {
author: $scope.author,
title : $scope.title,
body : $scope.body
}
}
$http.post("/", data).success(function(data, status) {
console.log('Data posted successfully');
})
}
});
</script>
</head>
<body ng-app="myApp">
<div ng-controller="myCtrl">
<form>
Author:
<input type="text" ng-model="author">
<br>
<br> Title:
<input type="text" ng-model="title">
<br>
<br> Body:
<input type="author" ng-model="body">
<br>
<br>
<input type="submit" value="Submit" ng-click="submit()">
</form>
</div>
</body>
</html>
我運行它在我的node.js代碼是
server.js
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var path = require('path');
app.use(express.static(__dirname + './public'));
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.get('/', function(req, res){
res.sendFile(__dirname +'/index.html');
});
app.post('/', function(req,res){
console.log(req.body)
res.sendFile(__dirname +'/index1.html');
});
console.log('server running at 3000!')
app.listen(3000);
我得到正確的index.html,但在谷歌瀏覽器檢查它顯示我的錯誤
angular.js:38Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.5.6/ $injector/modulerr?p0=myApp&p1=Error%3A%2…ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.5.6%2Fangular.min.js%3A21%3A332)
我認爲你必須加載JavaScript庫文件,請檢查 –
嘿阿希什我應該加載javascript文件? –
我已經包含angular.min.js @AshishPatel –