I'm having some trouble updating my mongoDB from a Node server. Sorry, but I'm having some trouble tagging the code. Might come out as regular text. The error i get is on the node server and states as follows:
Cast to string failed for value "undefined" at path "text"
Here's my code:
web-server:
app.post('/updateArticle/', function(req, res){
console.log("Updating article");
articleModel.update(
{id: req.id},
{$set: {title: req.title, text: req.text}});
"services:
wikiServices.factory('articleService', function($http, $routeParams){
return{
getArticles: function(callback){
$http.get('articles/' + $routeParams.article).success(callback);
},
updateArticle: function(article, callback){
$http.post('updateArticle/', article);
}
};
controllers:
wikiControllers.controller('articleController', ['$scope', 'articleService', '$routeParams', '$sanitize',
function($scope, articleService, $routeParams, $sanitize){
articleService.getArticles(function(result){
$scope.article = result[0];
console.log($sanitize(result[0].text));
$scope.articleHTML = $sanitize(result[0].text);
});
$scope.update = function(article, callback){
articleService.updateArticle(article);
console.log("test");
};
articleEdit:
<div text-angular="text-angular" ng-model="article.text"></div>
<div ng-bind-html="article.text"></div>
<a href="#/articles/{{article.id}}">Tilbake</a>
<button ng-click="update()">Lagre forandringer</button>