0
我正在使用文章和用戶實現到Meanjs內置的應用程序。Meanjs內置的應用程序,如何更新文章中的USER數組模塊
<a data-ng-controller="MyArticlesController" data-ng-repeat="article in articles" class="list-group-item">
<button data-ng-click="addArt2me()" class="glyphicon glyphicon-plus addArt2me" ></button>
<h4 class="list-group-item-heading" data-ng-bind="article.title"></h4>
<p> {{article.content | limitTo:140}} </p>
</a>
這裏所述觸發功能$scope.addArt2me()
控制器:
'use strict';
angular.module('users').controller('MyArticlesController', ['$scope', 'Articles', 'Users', '$location',
function($scope, Articles, Users, $location) {
var myUser = new Users($scope.user);
$scope.addArt2me = function() {
var myArticle = new Articles($scope.article);
myUser.userArticles.push(myArticle._id);
myUser.$update(function(response) {
console.log("Actualize!! con : " + user.userArticles.length + "__" + response);
}, function(errorResponse) {
console.log("updatError: " + errorResponse);
$scope.error = errorResponse;
});
}
}
]);
在用戶的模型我有一個數組的與每一個項目的按鈕文章(查看)
名單articles._id userArticles
。
該視圖使用一個按鈕觸發控制器中的功能addArt2me()
,該按鈕推送並更新'userArticles'內的myArticle._id。
它的工作原理成功並保存元素放入DB :)
console: Actualize!! con : 60__[object Object]
...但只有第一次,下一次它會觸發一個錯誤:(
PUT http://localhost:3000/users 400 (Bad Request)
updatError: [object Object]´
我需要處理某種服務來更新ARTICLES模塊中的USERS模塊? 我不能只用Mongoose更新用戶的模型嗎? 爲什麼它對第一個保存的文章有效?
任何指南非常讚賞。謝謝!
你可以添加你的後端控制器的代碼嗎? –
當然,請看看[這裏](https://github.com/asael2/appnl/tree/master/app/models)謝謝! – Artyficial
對不起這些是模型,這裏的控制器https://github.com/asael2/appnl/tree/master/app/controllers – Artyficial