Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

While loading my index.html i am facing this error

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>

I am running it on my node.js code which is

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);

I am getting index.html correctly but in google chrome inspection it is showing me error

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)

share|improve this question
1  
i think you have to load javascript library file, please check – Ashish Patel 18 hours ago
    
Hey Ashish Which javascript file should I load? – Abhishek Parikh 18 hours ago
    
I've included angular.min.js already @AshishPatel – Abhishek Parikh 18 hours ago
    
<script src="code.jquery.com/jquery-2.2.4.js"></script>; you can either download library into your local :code.jquery.com/jquery-2.2.4.js , – Ashish Patel 18 hours ago
1  
Jquery? I haven't used that in my code – Abhishek Parikh 18 hours ago
up vote 1 down vote accepted

Your code is working fine in our machines.

As you said in one comment that you are getting the old files always, it should be cache problem

If it is the cache problem, steps to clear cache in 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.

If you want to remove cached views from the code.

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.

Also you can,

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
share|improve this answer
    
I've tried all the old data was deleted my passwords and all still somehow browser loads mine old file – Abhishek Parikh 16 hours ago
    
old file means? the html or the data? – Sravan 16 hours ago
    
old html and js file – Abhishek Parikh 16 hours ago
    
open your browser console, go to network tab, refresh the page, and while refreshing, right click on network tab and click on, clear browser cookies, then press alt+f5 – Sravan 16 hours ago
1  
okay great, every time you fave a cache issue, try the steps in above comment. – Sravan 16 hours ago

Same code works here

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');
    })
  }
});
<!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>

share|improve this answer
    
This answer doesn't make sense, rather you should add plunkr in comment, and ask OP for more inputs – Pankaj Parkar 18 hours ago
    
@sajeetharan Does that mean I should try with another file named script.js – Abhishek Parikh 18 hours ago
    
I've tried not working @sajeetharan – Abhishek Parikh 18 hours ago
    
@AbhishekParikh Not necessary see here jsfiddle.net/sajeetharan/tc6z0r66 – Sajeetharan 18 hours ago
    
@AbhishekParikh check if your angular script file is loaded in the network tab – Sajeetharan 18 hours ago

Simply add this line after your angular.js script line:

<script src="https://code.jquery.com/jquery-2.2.4.js"></script>

it will work..

share|improve this answer
    
why jquery here? – Sajeetharan 18 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.