3

This is ui-select where user can select an options:

<ui-select ng-model="state.selected" ng-change="openModal(state.selected,orders.order_id)" ng-if="orders.state == 'Paid'" theme="selectize" ng-disabled="disabled" style="width: 300px;"> .....

Whenever there is changes, it trigger modal from bootstrap

$scope.openModal = function(name,oid){
    $scope.modalInstance = $modal.open({
        templateUrl: 'reservationModal.html',
        scope:$scope,
        name: function(){
            return name;
        }
    });
}

$scope.cancel = function(){
    $scope.modalInstance.dismiss();
}

$scope.confirmChg = function(){
    console.log('ok...');
}

The template is as follow:

<script type="text/ng-template" id="reservationModal.html">
    <div class="modal-header">
        <h3 class="modal-title">Confirmation</h3>
        <!--<button class="btn btn-warning" ng-click="close()">X</button>-->
    </div>
    <div class="modal-body">
        Confirm to change status to {{name}} ?

    </div>
    <div class="modal-footer">
        <button class="btn btn-danger" type="button" ng-click="confirmChg(status_oid,status)">Yes</button>
        <button class="btn btn-warning" type="button" ng-click="cancel()" data-dismiss="modal">No</button>
    </div>
</script>

The problem is , the {{name}} in template is not displaying. How can I pass variable from open modal function?

1

1 Answer 1

5

You need to set the name on the scope, just add the line:

$scope.name = name;

before calling $scope.open. So the openModal function would look like:

$scope.openModal = function(name,oid){
    $scope.name = name;
    $scope.modalInstance = $modal.open({
        templateUrl: 'reservationModal.html',
        scope:$scope,
        name: function(){
            return name;
        }
    });
}
Sign up to request clarification or add additional context in comments.

2 Comments

where I set it? inside name function?
Just at the beginning of openModal. I just clarified the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.