2
我有一個配置,如下plunkr:http://plnkr.co/nya3cr如何在UI視圖中顯示自定義指令?
中,我有作爲的狀態:
.state('main.layout', {
url : '/l',
abstract : true,
views : {
'left' : {
templateUrl : 'left.html',
controller : 'LeftCtrl'
},
'right' : {
templateUrl : 'right.html',
controller : 'RightCtrl'
},
'middle' : {
templateUrl : 'middle.html',
controller : 'MiddleCtrl'
},
'bottom' : {
templateUrl : 'bottom.html'
}
}
})
我想使用這樣的UI的視圖定製指令。
.directive('sidebarDirective', function() {
return {
template: 'Hello hello!',
restrict: 'E',
link: function postLink(scope, element, attrs) {
element.text('this is the sidebarDirective directive');
}
};
});
,但我不能一個用戶界面視圖元素中使用它,比如在我的配置,我試圖讓我的自定義指令(側邊欄指令)在left.html
<div sidebar-directive></div>
以及如在right.html中,但它不顯示。我可能會忽略關於如何在UI視圖狀態中包含指令的一些關鍵理解。請幫忙。
非常感謝您匹配!假設如果我必須控制指令顯示時的邏輯,我應該在哪裏寫這個邏輯? – 2014-11-24 07:48:00
我會這樣說:由您創建的指令,用於您的應用程序 - 適合您。所以完全取決於你的需求。沒有一般規則。上下文應該決定。我會說;)希望它有一點幫助;)與'UI-Router'好運,真棒工具... – 2014-11-24 07:50:12