opening a modal in a route in AngularJS with angular-ui-bootstrap

后端 未结 4 1544
逝去的感伤
逝去的感伤 2020-12-29 13:56

I am trying to do what was essentially answered here Unable to open bootstrap modal window as a route

Yet my solution just will not work. I get an error

4条回答
  •  忘掉有多难
    2020-12-29 14:28

    You may create a state with the same templateUrl and controller as your page where you want to show the modal, adding params object to it

    $stateProvider
        .state('root.start-page', {
            url: '/',
            templateUrl: 'App/src/pages/start-page/start-page.html',
            controller: 'StartPageCtrl'
        })
        .state('root.login', {
            url: '/login',
            templateUrl: 'App/src/pages/start-page/start-page.html',
            controller: 'StartPageCtrl',
            params: {
                openLoginModal: true
            }
        })
    

    And in controller of the page, use this parameter to open the modal

    .controller("StartPageCtrl", function($scope, $stateParams) {
        if ($stateParams.openLoginModal) {
            $scope.openLoginModal();
        }
    

提交回复
热议问题