0

i am using modal in angular but when modal open so here values are not binding with model i don't know why this happening must be appreciates if some corrected if there is any mistake thanx.

modal.html

<script type="text/ng-template" id="categoryModal.html">

    <form class="form-horizontal" name="category_form" novalidate>
        <div class="modal-header">
            <a class="close" ng-click='cancel()'><i class="icon-remove-circle icon-bold"></i> </a>
            <h3>Category</h3>
        </div>

        <div class="modal-body">

            <div class="form-group">
                <label for="category_Name" class="col-lg-3 form-label">Category Name:</label>
                <div class="col-lg-8">
                    <input class="form-control" id="category_Name" ng-model="category.name" name="category_Name" placeholder="Category Name" required/>
                    <div class="error" ng-show="category_form.category_Name.$dirty && category_form.category_Name.$invalid">
                        <small class="error errorFields" ng-show="category_form.category_Name.$error.required">
                            Category Name is required.
                        </small>

                    </div>
                </div>
            </div>

        </div>

        <div class="modal-footer">
            <button  ng-click='saveCategory()' class="btn btn-primary" ng-disabled="category_form.$invalid">
                <i class="icon-ok-sign icon-white"></i> Add
            </button>

            <button ng-click='cancel()' class="btn btn-warning">
                <i class="icon-remove-circle icon-white"></i> Cancel
            </button>
        </div>

    </form>
</script>

modalController.js

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

    // Save Brand

    $scope.saveCategory = function () {
       console.log($scope.category) // undefined
    };

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

});
Wajihurrehman
  • 567
  • 3
  • 15
  • 29

1 Answers1

0

I would try adding the same $scope to modalOptions and letting the modal share the controller's $scope variables. Putting both onto $rootScope is too drastic. Ideally, your modal should have an isolate scope, but it sounds like you need some overlap.

D. Browne
  • 1
  • 2