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

后端 未结 3 2170
栀梦
栀梦 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:29

    If you are using ui-router you can easily use the resolve from ui-router to provide a $uibModalInstance (was $modalInstance before):

    $stateProvider
    .state('conductReview', {
        url: '/review',
        templateUrl: '/js/templates/review.html',
        controller: 'yourController',
        resolve: {
            $uibModalInstance: function () { return null; } // <- workaround if you want to use $uibModalInstance in your controller.
        }
    })
    

    That way you can use your modal controller like a normal controller. If you inject $uibModalInstance in your controller it will be null.

提交回复
热议问题