Reputation: 171321
I would like to create a confirmation-dialog-header
directive that will open a Bootstrap UI Modal that will be used like this:
<button class="btn" confirmation-dialog-header="Non Working Dialog">
Non Working Dialog
</button>
Here is what I'm trying to do (CoffeeScript): Live Demo
app.directive 'confirmationDialogHeader', ->
restrict: 'A'
link: (scope, element, attrs) ->
$confirmationDialog = $ """
<div modal="confirmationDialog">
<div class="modal-header">
<h4>#{attrs.confirmationDialogHeader}</h4>
</div>
<div class="modal-body">
I want to be hidden by default
</div>
<div class="modal-footer">
<button class="btn" ng-click="confirmationDialog = false">
OK
</button>
</div>
</div>
"""
$(document.body).append($confirmationDialog)
$(element).click ->
scope.confirmationDialog = yes
Unfortunately, the modal is not hidden by default, and clicking the button doesn't seem to have any effect.
Any help would be appreciated.
Upvotes: 0
Views: 5970
Reputation: 15931
You should use the dialog
service. To hide the modal in your directive, wrap the entire dialog in a <div>
with the classes hide,modal,fade
.
Upvotes: 0
Reputation: 23871
$compile
them to kick in AngularJS.scope.$apply
need to be invoked to trigger AngularJS evaluation loops.Thus
app.directive 'confirmationDialogHeader', ($compile) -> # 1
$(document.body).append($confirmationDialog)
$compile($confirmationDialog)(scope) # 1
$(element).click ->
scope.confirmationDialog = yes
scope.$apply() # 2
Upvotes: 2