加载我的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:38未捕获错误:[$ injector:modulerr] http://errors.angularjs.org/1.5.6/ $注射器/ modulerr P0 = MyApp来&安培; P1 =错误%3A%2 ... ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.5.6%2Fangular.min.js%3A21%3A332)
答案 0 :(得分:1)
相同的代码在这里工作
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');
})
}
});
&#13;
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
<script src="script.js"></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>
&#13;
答案 1 :(得分:1)
只需在angular.js脚本行之后添加以下行:
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
它会起作用..
答案 2 :(得分:1)
您的代码在我们的计算机上运行良好。
正如您在一条评论中所说的那样,您总是得到旧文件,它应该是cache problem
如果是缓存问题,请执行 Chrome 中清除缓存的步骤。
1) Open Chrome.
2) On your browser toolbar, tap More .
3) Tap History, and then tap Clear browsing data.
4) Under "Clear browsing data," select the checkboxes for Cookies and site data and Cached images and files.
5) Use the menu at the top to select the amount of data that you want to delete. ...
6) Tap Clear browsing data.
如果要从代码中删除缓存的视图。
app.run(function($rootScope, $templateCache) {
$rootScope.$on('$routeChangeStart', function(event, next, current) {
if (typeof(current) !== 'undefined'){
$templateCache.remove(current.templateUrl);
}
});
});
Here is a link where you get these sort of answers.
你也可以,
1) Open your browser console
2) Go to network tab
3) Refresh the page
4) While refreshing, right click on network tab and click on, clear browser cookies, then press alt+f5