خرید بک لینک

Vote count: 0

This is the server.js file

var express = require('express');
var app = express();
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
app.use(bodyParser.json());

mongoose.coect("mongodb://localhost/test");

var todoschema = new mongoose.Schema ({
 name : {type: String, required: true}
 });

var todomodel = mongoose.model('todolist',todoschema);

app.get('/',function(req,res){

    res.sendFile('C:\Users\Rohit\Desktop\New folder\files\index.html');  
})

app.get('/todolist', function (req, res){
    todomodel.find(function(err,tasks){
      res.json(tasks);
     });
});

app.post('/todolist', function (req, res) {
  
  todomodel.insert(req.body, function(err, task) {
    res.json(task);
  });
});

app.delete('/todolist/:id', function (req, res) {
  
 todomodel.remove(req.params.id, function (err, task) {
    res.json(task);
  });
});

app.get('/todolist/:id', function (req, res) {
  
  todomodel.findById(req.params.id, function (err, task) {
    res.json(task);
  });
});

app.put('/todolist/:id', function (req, res) {
  
  todomodel.findAndModify({
     query: req.params.id,
     update: {$set: {name: req.body.name}},
     new: true}, function (err, task) {
      
      res.json(task);
    }
  );
});

app.listen(3000);
console.log("Server ruing on port 3000");

this is the index.html file

<!DOCTYPE html>
<html ng-app="App">
<head>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
<script >
        var App = angular.module('App',[]);
App.controller('Ctrl',['$scope','$http',function($scope,$http) {
         
    var reset = function(){
      $http.get('/todolist').success(function(response){
        $scope.todolist=response;
        $scope.task="";
        });
     };

  reset();

$scope.addtask = function() {
  
  $http.post('/todolist', $scope.task).success(function(response) {
        console.log("added");
       reset();
    });
 };

$scope.deletetask = function() {
  $http.delete('/todolist/'+ id).success(function(response){
      reset();
      });
   };
 
$scope.edittask = function(id) {
   $http.get('/todolist/'+ id).success(function(response){
       $scope.task=response;
     });
   };

$scope.updatetask = function(id){
   $http.put('/todolist/'+$scope.task._id, $scope.task).success(function(response){
       reset();
    });
 };

$scope.clearfield = function(){
   $scope.task="";
}

}]);


</script>

<style>
#list   
{ margin-left:320px;
  font-size: 40px;
  font-family:verdana;
}
button     
{ color:yellow;background-color:red;text-align:center;cursor:pointer;
  -webkit-transition-duration: 0.4s;
  transition-duration: 0.4s;
  font-size:40px;
  padding: 14px 32px;
}
button:hover
{ background-color:peachpuff;
  color:tomato;
}
</style>
</head>

<body style="background-color:cyan;">

<div ng-controller="Ctrl">

<h1 style="text-align:center;font-family:verdana;">To-Do LiSt</h1>

<div style="margin-left:300px">
<input type="text" ng-model="task.name" style="background-color:black;color:white;font-size:40px;width:40%">
<button ng-click="addtask()">Add</button>&nbsp;
<button ng-click="updatetask()">Update</button>&nbsp;<button ng-click="clearfield()">Clear</button>
</div>

<ul>
<li id="list" ng-repeat="task in todolist">
{{task.name}}
<button ng-click="deletetask(task._id)">Delete</button>&nbsp;&nbsp;<button ng-click="edittask(task._id)">Edit</button>
</tr>
</table>

</div>


</body>
</html>

these are the errors i get in the console

http://localhost:3000/todolist Failed to load resource: the server responded with a status of 500 (Inteal Server Error)
http://localhost:3000/todolist/undefined Failed to load resource: the server responded with a status of 500 (Inteal Server Error)
Failed to parse SourceMap: https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js.map

I ran the server.js file from my CMD, and when i opened the localhost:3000 , i got my html file as a webpage , but the buttons weren't working and whenever i pressed the buttons , the above errors got displayed in the console. I figured out that the angularjs part isn't working , but i don't know how to resolve it , please suggest me a solution to make my todolist page work

asked 6 mins ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 12 خرداد 1395 ساعت: 0:12

صفحه بندی