Created
March 24, 2014 10:18
-
-
Save Unitech/9737679 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// partie express | |
var articles = []; | |
var id = 0; | |
app.post('/article/new', function(req, res) { | |
var article = req.body; | |
article.id = id; | |
id++; | |
articles.push(article); | |
res.send({ success : true }); | |
}); | |
app.get('/article/:id', function(req, res) { | |
var id = req.param('id'); | |
articles.forEach(function(article) { | |
if (article.id == id) { | |
return res.send(article); | |
}) | |
}); | |
}); | |
// Front Angularjs | |
MyCtrl.controller('$http', function($http) { | |
// recupere un article | |
$scope.getArticle = function(id) { | |
$http.get('/article/' + id).success(function(data) { | |
console.log(data); | |
}) | |
} | |
// creer un article | |
$scope.createArticle = function(monarticle) { | |
$http.post('/article/new', monarticle).success(function(article) { | |
console.log(article) | |
}) | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment