Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.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
Javascript ngRepeat不';t循环数组_Javascript_Json_Angularjs_Node.js_Mongodb - Fatal编程技术网

Javascript ngRepeat不';t循环数组

Javascript ngRepeat不';t循环数组,javascript,json,angularjs,node.js,mongodb,Javascript,Json,Angularjs,Node.js,Mongodb,我有一个目标: { "_id" : ObjectId("5454e173cf8472d44e7df161"), "questionType" : 0, "question" : "question1", "answers" : [ { "content" : "answer1" }, { "is_true" : "true", "conten

我有一个目标:

{
    "_id" : ObjectId("5454e173cf8472d44e7df161"),
    "questionType" : 0,
    "question" : "question1",
    "answers" : [ 
        {
            "content" : "answer1"
        }, 
        {
            "is_true" : "true",
            "content" : "answer2"
        }, 
        {
            "content" : "answer3"
        }
    ],
    "matches" : [],
    "__v" : 0
}
该控制器:

var questionIndexController = function ($scope, Question, $routeParams) {
    var question = Question.get({id: $routeParams.id});
    $scope.question = question;
};


angular.module("adminMain")
    .controller("questionIndexController", ["$scope", "Question", "$routeParams", questionIndexController]);
这个标记:

<h3>Question:</h3>
<p>{{ question.question }}</p>
<ul>
    <li np-repeat="answer in question.answers">
        <span ng-show="answer.is_true">✓</span>
        <span>{{ answer.content }}</span>
    </li>
</ul>
你知道怎么解决这个问题吗


编辑

这是问题工厂代码:

var questionFactory = function($resource, restUrls) {
    return $resource(restUrls.question.index, {}, {
        save: {
            url: restUrls.question.add,
            method: "POST",
            isArray: false
        }
    });
};

angular.module("adminMain").factory("Question", ["$resource", "restUrls", questionFactory]);
其中
restUrls.question.index
“/api/questions/:id”

以及获取单个问题的node.js后端代码:

function indexQuestions(req, res, next) {
    var questionId = req.params.id || null;
    if(!questionId) next(errorHandler(404, "Not found"));
    Question.findOne({ _id: questionId }, function(err, question) {
        if(err) return next(err);
        if(question.length === 0) return next(errorHandler(404, "Question not found"));
        res.json(question);
    });
}
当我从
$resource
方法返回
console.log(问题)
时,我得到一个普通的promise对象:

以下内容中有一个输入错误:

<h3>Question:</h3>
<p>{{ question.question }}</p>
<ul>
    <li np-repeat="answer in question.answers">
        <span ng-show="answer.is_true">✓</span>
        <span>{{ answer.content }}</span>
    </li>
</ul>
问题:
{{question.question}}

  • ✓ {{answer.content}
应该有
ng repeat
而不是
np repeate

有一个输入错误:

<h3>Question:</h3>
<p>{{ question.question }}</p>
<ul>
    <li np-repeat="answer in question.answers">
        <span ng-show="answer.is_true">✓</span>
        <span>{{ answer.content }}</span>
    </li>
</ul>
问题:
{{question.question}}

  • ✓ {{answer.content}

应该有
ng repeat
而不是
np repeate

Question.get返回什么?你能显示问题的代码吗?get方法?@MichalCharemza Done,请再次检查问题。你能存储plunkr吗。。我真的看不出代码有任何问题…Question.get返回什么?你能显示问题的代码吗?get方法?@MichalCharemza Done,请再次检查问题。你能存储plunkr吗。。我真的看不出代码有任何问题…哦,哇!注意到这一点真是令人尴尬和印象深刻!当然解决了。非常感谢。哦,哇!注意到这一点真是令人尴尬和印象深刻!当然解决了。谢谢。