0

I have a button.On button click I open the model , in that model i have text field and submit button .I need to set the value of input field to input field which is on screen after click of submit button.how to make controller of model and where we write the click event of submit button ? here is plunker http://plnkr.co/edit/8FnZ2disRS3ALdRWVvpT?p=preview

  var app= angular.module('app',['ui.bootstrap']);
    app.controller('cntr', function($scope, $modal){
           $scope.onButtonClick = function () {

        $modal.open({
            templateUrl: 'myModalContent.html',
            backdrop: true,
            windowClass: 'modal',


        });
    };
      })
how to set value in input field?

2 Answers 2

1

While opening modal add controller and data to be send as resolve

$modal.open({
            templateUrl: 'myModalContent.html',
            backdrop: true,
            windowClass: 'modal',
            controller: getDataController,
                     resolve: {
                         items:
                             function () {
                                 return {
                                    //getUserData is some function to fill input value on main screen in main controller which takes submitted value as parameter
                                     someParameterInItems:$scope.getUserData,
                                 };
                             }
                     }
                 });


        });
//example controller

var getDataController = function ($scope,$modalInstance,items) {
 $scope.onClickFunctionInModal=function(){
    items.someParameterInItems(submittedValue);
}

}

In that getDataController define function for ng-click (or any submit function) on submit ,data gets submitted to that defined function in this case 'onClickFunctionInModal' which will invoke main 'getUserData' function with parameter

Hopes it helps

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

Comments

1

In a standard use, you need to publish your variable in the scope with ng-model in each input field. And when submitting the modal you get the input value returned by the modal returned promise.

Here is your plunker updated :

        $modal.open({
            templateUrl: 'myModalContent.html',
            backdrop: true,
            windowClass: 'modal',
            controller: ModalInstanceCtrl
        })
        .result.then(function(updatedItem){
          $scope.myLocalVar = updatedItem;
        });

http://plnkr.co/edit/toQOBNzcGtsTgSJiMB5H?p=preview

Comments

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.