0

Hi i want to open and close the bootstrap model popup by using angularjs controller.js code.

my controller code

app.controller('RoleViewCtrlq', ['$scope', '$modalInstance', '$modal',
function ($scope, $modalInstance, $modal) {


    $scope.open = function () {
        debugger;
        var modalInstance = $modal.open({
            templateUrl: 'myModalContent.html',
        });


        $scope.ok = function () {
            $modalInstance.close();
        };

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


    }
}
]);

Here i have create the sample https://plnkr.co/edit/xRhCR7qidlr24M8nAOA6?p=preview

it is not working to open and close my pop up in controller.js code. can any one check the issue.??

2 Answers 2

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

Remove this script tag from HTML and try again. It is working

Sign up to request clarification or add additional context in comments.

6 Comments

:@ Aswathy Balan : i want to close the model popup by using controller can you provide the answer
Add "novalidate" to your form element. Then you can close your modal. And use angularJs form validations for validating the form. <form name="profileformAdd" novalidate>
already i set the form validation. I want to close the popup in controller.js. Did you understand
You can close your modal using your OK and CANCEL function that you have already defined in your controller. But now on closing modal HTML5 default form validations are performing, that is why you are not able to close the modal. So add "novalidate" to your form element.
I have updated your code. Please try this one and tell me is this ok or not. plnkr.co/edit/rznnIzrZlgXcY3l8RT9b?p=preview
|
0

In the Plunker you have provided, you have not set any myModalContent.html.

When using:

var modalInstance = $modal.open({
    templateUrl: 'myModalContent.html'
});

Angular will check for a myModalContent.html file to include in the modal. It means creating the modal from a template.

After reviewing your code, I think this is not exactly what you are trying to achieve:

Forked your Plunker

3 Comments

:@mistails : i want to close the model popup by using controller can you provide the answer
Hi Mistalis, this is closed after the page refreshed. I want to close the pop up without refresh the page
@Vinoth: Hi Vinoth, whats your problem implementing in this way... jsfiddle.net/wjohtz0y I see in your plunkr code you don't have any $modal.open or templateUrl, which is needed.

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.