1

I have modal invoked with just HTML tags:

<button class="btn btn-xs stop" data-template-url="template/modal.html"
        bs-modal="modal">
</button>

but after that I can only close my modal with "Close" button, not "Save changes".

This is my external modal template:

<div class="modal" id="modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document" ng-controller="modalController">
    <div class="modal-content">
        <div class="modal-header">
           <h4 class="modal-title" id="task_id"> Task #{{clickedStop}}</h4>
        </div>
        <div class="modal-body">
            <textarea  id="description" class="form-control" placeholder="Description of work on a task"></textarea>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" ng-click="$hide()">Close</button>
            <button type="button" class="btn btn-primary" ng-click="saveModal()">Save changes</button>
        </div>
    </div>
</div>

and my modalController:

app.controller('modalController', function($scope, $rootScope){

$scope.saveModal = function (){

    $scope.ticket_id = $rootScope.clickedStop;
    var tickets = localStorage.getItem($scope.ticket_id);
    var task = JSON.parse(tickets);

    $scope.description = jQuery("#description").val();
    if($scope.description == "" || $scope.description == undefined)
    {
        alert("You must enter description!");
        return;
    };

    var save = JSON.stringify({
        ":task_id":$scope.ticket_id,
        ":creator":task.creator,
        ":date_created":task.start,
        ":owner":task.owner,
        ":title":task.title,
        ":description":$scope.description
    });

        jQuery.ajax({
            url:"engine/saveActivity.php",
            method: "POST",
            data:{data:save},
            dataType:'json'
        })
            .success(function (responce){
            if (responce === true){
                console.log("Activity saved!");
                //I wont to close modal here

            }

        }).error(function(data){
               console.log("Error Activity save!"+ data);
            });

};

When I tried to use $hide(), I get an error that $hide is not a function.

davidkonrad
  • 83,997
  • 17
  • 205
  • 265

1 Answers1

1

$hide() does not work because you not have included the $modal service :

app.controller('modalController', function($scope, $rootScope, $modal) {
                                                               ^^^^^^

Now ng-click="$hide()" will work as expected. As the docs points out :

Append a bs-modal attribute to any element to activate the directive.

The module also exposes a $modal service Available for programmatic use (inside a directive/controller).

But you must include it in order to use it.

davidkonrad
  • 83,997
  • 17
  • 205
  • 265