I'm trying to create a custom module that is fairly similar to the modal provided in the ui.bootstrap library. I would like to be able to open and close it via a service, and pass some options. The problem, is, I'm somewhat new to angular, and I'm not entirely sure how this should be done.
I've read up on how to create a custom modules (this was a great post), And I understand that I'm going need a service in order to open it programatically, But after looking at the source code for I'm somewhat lost. I'm assuming I'll need to do the following:
- Build a service to append an element to the body
- That element should have a directive that will trigger... something or other?
But when I gave that a try, the directive didn't actually link up. For example:
angular.module("ui.sidePanel", [])
.service("$sidePanel", function($rootScope, $document){
return{
open: function(options){
angular.element($document[0].body).append("<side-panel></side-panel>");
console.log('Boop');
}
}
})
.directive("sidePanel", function(){
return {
restrict: "E",
link: function(scope, element, attrs){
console.log('Side Panel');
}
}
})
Would never log "Side Panel".