M.E.A.N没有更新

时间:2015-09-08 18:43:45

标签: javascript angularjs mongodb express angularjs-scope

我对一张名为'评论'的图片有一系列评论 我还有一个名为“newcmt”的属性,我想进入评论

我有一个函数addComment尝试并且无法进行这些更改。

我尝试了几种不同的方法,但是尽管在响应中返回了适当的更改,但看起来并没有更新api。 我只是更新参考? 异步性质会导致错误吗? 我的mongo计划错了吗? 将评论作为自己的终点更容易吗?

JS

LASTFOLDER=base64 --decode"
HTML     
var refresh = function() {
  $http.get('/api/things').success(function(awesomeThings) {
    $scope.awesomeThings = awesomeThings;

  });
};


$scope.addThing = function() {
  if($scope.newThing === '') {
    return;
  }
  $http.post('/api/things/', { name: $scope.newThing });

  refresh();
};


$scope.addComment = function(thing) {
  if(thing.newcmt == '') {
    return;
  }
  $scope.newcmt = thing.comment;
  $scope.newcmt.push(thing.newcmt);
  console.log($scope.newcmt)
  $http.put('/api/things/' + thing._id, {comment : $scope.newcmt }, {safe: true, upsert: true, new : true}).success(function(response) {

    console.log(response);
    refresh();

  })
};

$scope.deleteThing = function(thing) {
  $http.delete('/api/things/' + thing._id);
  refresh();
};

MODEL

<div class="container">
  <img class="img-responsive" src="{{thing.url}}" alt="">
</div>
<div class="col-md-12"  ng-repeat="comment in thing.comment">
  <p>{{comment}}</p>
</div>
<div class="row">
  <div class="col-xs-12">
   <i class="fa fa-comment-o fa-3x"></i>
   <input type="text" placeholder='...' ng-model="thing.newcmt" >
   <button class="btn btn-default" ng-click="addComment(thing)">+</button>
   <i class="fa fa-arrow-down fa-2x pull-right"></i>
   <i class="fa fa-arrow-up fa-2x pull-right"></i>
   </div>
</div>

PUT

var mongoose = require('mongoose'),
Schema = mongoose.Schema;

var ThingSchema = new Schema({
name: String,
url: String,
credit: String,
active: Boolean,
comment: Array,
newcmt: String
});

module.exports = mongoose.model('Thing', ThingSchema);

完整的github: https://github.com/jneljneljnel/meangen

0 个答案:

没有答案