2015-08-21 19 views
0

我想寫一個指令來創建在角度中的選項卡,但它每次運行代碼時給它提供$ compile:ctreq。 這裏是我的代碼app.js

(function(window) { 

angular.module('app', []) 
.directive('tab', function() { 
    return { 
restrict: 'E', 
transclude: true, 
template: '<h2>Hello world!</h2> <div role="tabpanel" ng-transclude></div>', 
require: '^tabset', 
scope: { 
    heading: '@' 
}, 
link: function(scope, elem, attr,tabsetCtrl) { 
    //tabsetCtrl.addTab(scope) 
} 
    } 
}) 
.directive('tabset', function() { 
return { 
restrict: 'E', 
transclude: true, 
scope: { }, 
templateUrl: 'tabset.html', 
bindToController: true, 
controllerAs: 'tabset', 
controller: function() { 
    var self = this 
    self.tabs = [] 

    /* self.addTab = function addTab(tab) { 
     self.tabs.push(tab) 
    } */ 
    } 
    } 
}) 
})(window); 

,這裏是我的index.html

<html> 
<head> 
<title>Tabs Directive</title> 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0-rc.0/angular.min.js"></script> 
<script src="app.js"></script> 
</head> 
<body ng-app="app"> 
    <h1>Tabs, tabs, tabs!</h1> 
</tabset> 
<tab heading="Tab 1"> 
    Lorem ipsum dolor sit amet, ut eam nullam utroque liberavisse, ea 
    </tab> 
<tab heading="Tab 2"> 
    Just another tab! 
</tab> 
</tabset> 
</body> 

這裏是我的tabset.html

<div role="tabpanel"> 
    <ul class="nav nav-tabs" role="tablist"> 
    <li role="presentation" 
     ng-repeat="tab in tabset.tabs"> 

     <a href="" 
     role="tab" 
     ng-click="tabset.select(tab)">{{tab.heading}}</a> 
    </li> 
    </ul> 

    <ng-transclude> 
    </ng-transclude> 
</div> 

我不能明白我在做什麼錯。 其實有我的目標

  1. 創建一個標籤系統,如chrome.where我可以動態地添加標籤和標籤的模板也將是動態的。
  2. 每個模板都會有不同的控制器。

回答

0

index.html的標籤集的標籤都結束標記,這意味着角不編譯的標籤集,並且選項卡指令不能要求標籤集:

</tabset> <!-- closing tag should be <tabset> --> 
<tab heading="Tab 1"> 
    Lorem ipsum dolor sit amet, ut eam nullam utroque liberavisse, ea 
    </tab> 
<tab heading="Tab 2"> 
    Just another tab! 
</tab> 
</tabset> <!-- closing tag -->