我正在尝试获取有关货车的更多信息,方法是使用其ID来调用它所连接的车队。当我返回有关货车的信息时,我的代码现在正常工作。但是当我取消评论代码的注释行时它会中断,并给我这个错误https://docs.angularjs.org/error/ $ rootScope / infdig?p0 = 10& p1 =%5B%5D
为什么我无法拨打电话,我不明白为什么会破坏它,或者如何解决它。
Directives.directive(' displayCurrentVans',' Van',' Fleet',function(Van,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;
}
}
}
}
}]);
答案 0 :(得分:0)
1-你不应该在指令Names中使用CamelCase(虽然这不是你当前的问题);
2-在您的代码中,之后:&#34;返回van.id&#34;你不会写更多的代码,我的意思是,这是一个规则,在使用return之后,dunction将会中断并结束所以你在第一次返回之后不再编写任何代码
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;