Created
August 28, 2013 13:50
-
-
Save jloper3/6366256 to your computer and use it in GitHub Desktop.
AngularJS / AngularUI popover with templateURL. Uses the dialog service to style and position a dialog with bootstrap's popover css.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.controller('AppCtrl', ['$scope', '$dialog', function ($scope, $dialog) { | |
$scope.popover = function($event) { | |
var opts = { | |
backdrop: true, | |
// Style as a popover, bottom position | |
// additional show class to override popover class display:none | |
dialogClass: 'popover bottom show' | |
templateUrl: 'partials/popover.html', | |
controller: 'PopCtrl', | |
// Resolve the click event coordinates | |
resolve: { | |
posX: function () { | |
return angular.copy($event.x) | |
}, | |
posY: function () { | |
return angular.copy($event.y) | |
} | |
} | |
}; | |
var d = $dialog.dialog(opts); | |
d.open().then(function(result) { | |
if (result) { | |
console.log("Popover closed with "+result) | |
}); | |
} | |
}); | |
}]); | |
app.controller('PopCtrl', ['posX', 'posY', 'dialog', function posX, posY, dialog ) { | |
$scope.posX = posX; | |
$scope.posY = posY; | |
$scope.close = function () { | |
dialog.close(); | |
}; | |
}]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
popover.show { | |
display: block; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-style="{position: 'fixed', top: posY + 'px', left: posX + 'px'}"> | |
<div class="arrow"></div> | |
<h4 class="popover-title">Alarms</h4> | |
<div class="popover-content"> | |
<p>I'm in a popover!</p> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment