2014-04-08 27 views
0

我使用的是指令與分離範圍的NG-重複通在NG-重複模式的每一個屬性指令

<page ng-repeat='page in pages' id='{{page.id}}' title='{{page.title}}'></page> 

我的指令:

app.directive('page', function(){ 
    return { 
     restrict: 'EA', 
     scope: { 
      id: '@', 
      title: '@' 
     }, 
     templateUrl: 'views/tpl/page.html', 
     controller: 'PageController' 
}); 

有什麼辦法避免必須手動將所有屬性傳入指令的隔離範圍?我的目標是使用「page」對象中的每個屬性自動填充指令的作用域。

謝謝!

回答

1

您可以傳遞整個頁面對象。 Directives Guid

HTML:

<page ng-repeat='page in pages' page-object='page'></page> 

JS:

app.directive('page', function(){ 
return { 
    restrict: 'EA', 
    scope: { 
     pageObject: '=' 
    }, 
    templateUrl: 'views/tpl/page.html', 
    controller: 'PageController' 
});