How to use the same controller for modal and non-modal form in Angular UI Bootstrap?

后端 未结 3 2103
栀梦
栀梦 2020-12-09 08:42

I\'ve got a modal with a registration form. The same form should be displayed at the bottom of the landing page not in a modal.

Currently my controller that handles

3条回答
  •  暖寄归人
    2020-12-09 09:31

    If you want to use same controller for both modal form as well as landing page form, make use of

    modalInstance.result.then(function (selectedItem) { $scope.selected = selectedItem; }, function () { $log.info('Modal dismissed at: ' + new Date()); });

    You can get all the data from modal form in selectedItem and use this in landing page form. Also, how do you open the modal. If it is through a button, bind that ng-model to open modal using $modal.open.Don't create separate controller for your modal.Use the same one as your landing page. This way you can use 1 controller to open modal as well as other function after the modal is closed.

    PS: Code snippet given here is from angular ui's page. Check that page's documentation for selectedItem

提交回复
热议问题