Я создал пользовательскую директиву поверх модальной директивы ui bootstrap, поэтому я могу использовать один и тот же модальный шаблон везде в своем приложении.
Моя директива работает, пока я не попытаюсь включить ее содержимое в шаблон:
http://plnkr.co/edit/YPESA3?p=preview
Из index.html
<div ng-controller="ModalDemoCtrl">
<button class="btn" ng-click="open()">Open me!</button>
<my:modal open="shouldBeOpen" close="close()">
<h1>Content</h1>
</my:modal>
</div>
Код модуля:
angular.module('plunker', ['ui.bootstrap'])
.controller('ModalDemoCtrl', function($scope) {
$scope.open = function () {
$scope.shouldBeOpen = true;
};
$scope.close = function () {
$scope.closeMsg = 'I was closed at: ' + new Date();
$scope.shouldBeOpen = false;
};
$scope.items = ['item1', 'item2'];
})
.directive('myModal', function() {
return {
restrict : 'E',
templateUrl: 'myTpl.html',
//transclude: true,
scope : {
open : '=',
close : '&'
}
};
});
Модальный шаблон:
<div modal="open">
<div class="modal-header">
<h4>I'm a modal!</h4>
</div>
<div class="modal-body">
<!--<div ng-transclude/>-->
</div>
<div class="modal-footer">
<button class="btn btn-warning cancel" ng-click="close()">Cancel</button>
</div>
</div>
Раскомментируйте свойство transclude из директивы и шаблона, и вы увидите, что получили TypeError: undefined is not a function.
Я не могу понять, что я делаю неправильно.