Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing Modals with angular-modal-service (AngularJS)

I'm using (angular-modal-service) to create popups and modals via a service but I would like to know how it is possible to customize them? For instance, how can I change the modal-header color or remove the "by default" lines between the header, body and footer? Thank you.

Sample of the controllers:

var app = angular.module('app', ['angularModalService']);

app.controller('Controller', function($scope, ModalService) {

$scope.show = function() {
    ModalService.showModal({
        templateUrl: 'modal.html',
        controller: "ModalController"
    }).then(function(modal) {
        modal.element.modal();
        modal.close.then(function(result) {
            $scope.message = "You said " + result;
        });
    });
 };

});

app.controller('ModalController', function($scope, close) {

$scope.close = function(result) {
   close(result, 500); // close, but give 500ms for bootstrap to animate
};

});

Sample of the html:

<script src="https://code.angularjs.org/1.4.9/angular.min.js"></script>
<script src="https://rawgit.com/dwmkerr/angular-modal-service/master/dst/angular-modal-service.js"></script>

<div class="container" ng-app="app" ng-controller="Controller">

    <h3>Angular Modal Service</h3>
     <a class="btn btn-default" href ng-click="show()">Show a Modal</a>
     <p>{{message}}</p>

     <!-- The actual modal template, just a bit o bootstrap -->
     <script type="text/ng-template" id="modal.html">
         <div class="modal fade">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" ng-click="close('Cancel')" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Yes or No?</h4>
              </div>
              <div class="modal-body">
                <p>It's your call...</p>
              </div>
              <div class="modal-footer">
                <button type="button" ng-click="close('No')" class="btn btn-default" data-dismiss="modal">No</button>
                <button type="button" ng-click="close('Yes')" class="btn btn-primary" data-dismiss="modal">Yes</button>
              </div>
            </div>
          </div>
        </div>
     </script>

</div>
like image 781
Ariana Avatar asked Apr 16 '16 19:04

Ariana


People also ask

What is the use of custom modal in angular?

The custom modal directive is used for adding modals anywhere in an angular application by using the <modal> tag. Each modal instance registers itself with the ModalService when it loads in order for the service to be able to open and close modal windows, and removes itself from the ModalService when it’s destroyed using the scope ‘$destroy’ event.

How to display modals in angular using ng-template?

They simply get a reference to the modal component HTMLElement instance and use the classList methods add and remove to toggle its display on and off. We can use the ng-template to display modals in Angular.

How to open and close a modal window in AngularJS?

Opening & Closing AngularJS Custom Modals To open and close (show/hide) modal windows you need to use the ModalService by injecting it into your controller and calling the ModalService.Open () and ModalService.Close () methods, e.g:

What is modalservice in Salesforce?

Modal service which is responsible for creating/destroying modal. Modal component containing modal information ( body, title, buttons ) and, it sends events to modalService ( confirm / close ). Hosting component contains a reference to where the modal is going to appear and listen to modalService events. It does not know anything about the modal.


1 Answers

Your question is a CSS question.

To change modal colors or borders you have to add a custom CSS.

You can play with google dev tool to change styles and see the results in real-time so you don't have to reload the page.

To change header color:

.modal-header {
    background-color: red;
}

To hide border in footer:

.modal-footer {
    border-top: 0px!important;
}
like image 182
Ygalbel Avatar answered Oct 26 '22 10:10

Ygalbel