ng repeat中的angularjs指令服务

ng repeat中的angularjs指令服务,angularjs,angularjs-directive,Angularjs,Angularjs Directive,有谁能解释一下为什么会这样: //Common directives angular.module('mean.articles') .directive('checkout',['Cart', function(Cart) { return { restrict: 'A', template: '<div data-ng-repeat="item in items">' + '<

有谁能解释一下为什么会这样:

//Common directives
angular.module('mean.articles')
    .directive('checkout',['Cart', function(Cart) {
        return {
            restrict: 'A',
            template:   '<div data-ng-repeat="item in items">' +
            '<div class="clearfix item-box">'+
            '<div class="col-md-2 text-left item-pic"><img class="img-responsive img-rounded" alt="{{item.title}}" data-ng-src="/public/upload/{{item.pic}}"></div>'+
            '<div class="col-md-2 text-left item-quantity">{{item.quantity}}</div>'+
            '<div class="col-md-4 text-left item-title">{{item.title}}</div>'+
            '<div class="col-md-4 text-right item-tot" data-subtot="{{item.price * item.quantity}}">{{item.price * item.quantity}}</div>'+
            '</div>'+
            '</div>',
            link: function( scope , element , attributes ) {
                scope.items = Cart.get();
            }   
        };
    }]);
//通用指令
角度模块('mean.articles')
.directive('checkout',['Cart',函数(Cart){
返回{
限制:“A”,
模板:“”+
''+
''+
“{{item.quantity}}”+
“{{item.title}}”+
“{item.price*item.quantity}”+
''+
'',
链接:功能(范围、元素、属性){
scope.items=Cart.get();
}   
};
}]);
这不管用

//Common directives
angular.module('mean.articles')
    .directive('checkout',['Cart', function(Cart) {
        return {
            restrict: 'A',
            template:   '<div data-ng-repeat="item in Cart.get()">' +
            '<div class="clearfix item-box">'+
            '<div class="col-md-2 text-left item-pic"><img class="img-responsive img-rounded" alt="{{item.title}}" data-ng-src="/public/upload/{{item.pic}}"></div>'+
            '<div class="col-md-2 text-left item-quantity">{{item.quantity}}</div>'+
            '<div class="col-md-4 text-left item-title">{{item.title}}</div>'+
            '<div class="col-md-4 text-right item-tot" data-subtot="{{item.price * item.quantity}}">{{item.price * item.quantity}}</div>'+
            '</div>'+
            '</div>',
            link: function( scope , element , attributes ) {

            }   
        };
    }]);
//通用指令
角度模块('mean.articles')
.directive('checkout',['Cart',函数(Cart){
返回{
限制:“A”,
模板:“”+
''+
''+
“{{item.quantity}}”+
“{{item.title}}”+
“{item.price*item.quantity}”+
''+
'',
链接:功能(范围、元素、属性){
}   
};
}]);

模板只能访问其
范围

第二个示例不起作用,因为模板无法访问任何服务。像
购物车
这样的服务仅在指令的
链接
方法中可用