Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.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
Angularjs 在一个循环后重复停止,在指令中使用_Angularjs - Fatal编程技术网

Angularjs 在一个循环后重复停止,在指令中使用

Angularjs 在一个循环后重复停止,在指令中使用,angularjs,Angularjs,我试图通过使用面包车的id给它所属的车队打电话,获得更多关于面包车的信息。当我返回有关货车的信息时,我的代码立即起作用。但是当我取消注释代码的注释行时,它会中断,并给出以下错误$rootScope/infdig?p0=10&p1=%5B%5D 为什么我不能呼叫一个服务,我不明白为什么会中断它,或者如何修复它 指令.指令'displayCurrentVans',['Van','Fleet',functionVan,Fleet{ var render = '<div class="row"

我试图通过使用面包车的id给它所属的车队打电话,获得更多关于面包车的信息。当我返回有关货车的信息时,我的代码立即起作用。但是当我取消注释代码的注释行时,它会中断,并给出以下错误$rootScope/infdig?p0=10&p1=%5B%5D

为什么我不能呼叫一个服务,我不明白为什么会中断它,或者如何修复它

指令.指令'displayCurrentVans',['Van','Fleet',functionVan,Fleet{

var render =   '<div class="row">' +
    '<div class="col-lg-12">' +
        '<div class="alert alert-info alert-bottom-trimmer">' +
            '<table class="table table-hover table-condensed table-responsive text-center">' +
                '<thead ng-click="renderVans()" class="cursor">' +
                    '<tr>' +
                        '<th class="text-center">Van</th>' +
                        '<th class="text-center">Radio</th>' +
                        '<th class="text-center">User</th>' +
                    '</tr>' +
                '</thead>' +
                '<tbody ng-show="vanbox" ng-repeat="van in vans | limitTo: 4">' +
                    '<tr>' +
                        '<td>{{getVan(van)}}</td>' +
                        '<td>{{van.radio}}</td>' +
                        '<td>{{van.user_id}}</td>' +
                   '</tr>' +
                '</tbody>' +
            '</table>' +
        '</div>' +
    '</div>' +
'</div>';

return {
    scope: true,
    compile: function(tElem, atts){
        tElem.append(render);
        return function(scope, elem, attrs){
            scope.vans = Van.GetVans();
            scope.fleet = Fleet.GetFleets();

             console.log(Fleet.GetFleet({id: '1'}));

            scope.vanbox = false;
            scope.renderVans = function(){
                console.log("hello");
                scope.vanbox = !scope.vanbox;
            }
            scope.getVan = function(van){
              console.log("hi");
              return van.id
              //var number = Fleet.GetFleet({id: van});
              //return number.ident;
            }
        }
    }
}

}])

1-您不应该在指令名称中使用CamelCase,尽管这不是您当前的问题

2-在你的代码中,在:return van.id之后,你不能写更多的代码,我的意思是,这是一条规则,在使用return之后,dunction将中断并结束,因此你不能在第一次返回后再写更多的代码


谢谢你指点方向的名字,我不知道。另外,我应该澄清注释过的代码,当我取消注释它时,我还注释掉了第一条返回语句。我只是在试验,因为使用van.id的return语句它是有效的,但是当我把它注释掉并打电话给服务时,它就中断了。
         return van.id
          **No more codes here, because your function ends here**
            So below lines will never excecute
          //var number = Fleet.GetFleet({id: van});
          //return number.ident;