Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Meanjs内置应用程序,如何从文章模块更新用户数组_Node.js_Angularjs_Mongodb_Mongoose_Meanjs - Fatal编程技术网

Node.js Meanjs内置应用程序,如何从文章模块更新用户数组

Node.js Meanjs内置应用程序,如何从文章模块更新用户数组,node.js,angularjs,mongodb,mongoose,meanjs,Node.js,Angularjs,Mongodb,Mongoose,Meanjs,我正在将文章和用户实现应用到内置应用程序中 带有每个项目按钮的文章列表(视图): <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" >&l

我正在将文章和用户实现应用到内置应用程序中

带有每个项目按钮的文章列表(视图):

<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>
在用户模型中,我有一个文章数组。\u id
userArticles

该视图呈现一个文章列表,其中包含一个按钮,该按钮触发控制器中的函数
addArt2me()
,该函数将推送并更新myArticle.\u id(位于“userArticles”中)

它成功地工作并将元素保存到DB:)

…但这只是第一次,下次它触发错误时:(

我是否需要处理某种服务来更新文章模块中的用户模块? 我不能用Mongoose更新用户的模型吗? 为什么它对第一篇保存的文章很有效


非常感谢您的指导。谢谢!

经过两天的寻找,我刚刚创建了它

需要在分包商之外声明用户模型,因为它会对每一篇文章进行迭代

因此,将´$scope.myUser=新用户($scope.user)´´移动到“ArticlesController”中去完成任务


谢谢您的时间!

您可以添加后端控制器的代码吗?当然可以,请看一看谢谢!对不起,这些是型号,这里是控制器,前端的$scope.user在哪里?为什么不使用这个.user?
'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;
        });

    }
}
]);
console: Actualize!! con : 60__[object Object] 
PUT http://localhost:3000/users 400 (Bad Request)
updatError: [object Object]´