Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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 在同一个div中使用ng init和ng repeat_Javascript_Jquery_Angularjs - Fatal编程技术网

Javascript 在同一个div中使用ng init和ng repeat

Javascript 在同一个div中使用ng init和ng repeat,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我不确定是否可以在同一个div中使用ng init和ng repeat。我需要它从数据库中选择id为6的所有注释 我在这里调用代码并显示一个数组: < div ng-init="getComments('6')" ng-repeat="comment in comments">{{ comment.message }}< /div> 并在此处调用API: return { // get all the comments get : functio

我不确定是否可以在同一个div中使用ng init和ng repeat。我需要它从数据库中选择id为6的所有注释

我在这里调用代码并显示一个数组:

< div ng-init="getComments('6')" ng-repeat="comment in comments">{{ comment.message }}< /div>
并在此处调用API:

    return {
    // get all the comments
    get : function(statusid) {
        return $http.get('/api/comments' + statusid);
    },

我错过了一些简单的东西吗?我没有包括PHP文件,因为这些文件似乎都可以正常工作

ng init并不是为了这个目的,当然您可以将它和ng repeat一起使用,但ng repeat将首先被评估,因为它具有更高的优先级,原因显而易见。相反,您应该对触发列表显示的操作调用getComments。如果是在初始化时,则只需在控制器本身中进行调用。'/api/comments'+statusid,您是指'/api/comments/'+statusid',正如@PSL所说。这里的问题是,在getComments设置之前,注释是空的。这不会发生,因为注释为空时没有ng init元素。我想我没有正确使用GET。我更新了代码,但它仍然不起作用,但我认为它几乎已经存在了:get:functionstatusid{return$http{method:'get',url:'/api/comments',headers:{'Content Type':'application/x-www-form-urlencoded'},params:statusid};},
    return {
    // get all the comments
    get : function(statusid) {
        return $http.get('/api/comments' + statusid);
    },