0

I have a page that has a navbar on it. when you click on a button in the navbar it should redirect you to a search page, and open a modal dialog. I'm not sure what I'm doing wrong, but it won't redirect to the page I've specified in the ng-click directive and the modal only opens when it has the search page open. Here's my button in the navbar

<button class="btn default-btn advancedbtn" data-toggle="modal" data-target="#myModal" ng-click="redirect()">Advanced</button>

Here's the code to redirect in my controller:

$scope.redirect = function () {
           $location.url('/search');
       }

I'm probably going about this in the wrong way. If any other code is needed let me know. Thanks.

hollyquinn
  • 652
  • 5
  • 15
  • 48
  • You can't redirect AND open a modal, but you could redirect and THEN open a modal. Try going to /search?modal=true and then on the search page write some JS that will check for the modal query string parameter and open the modal if it's true. As far as the redirect not working, that answer is already on SO here: http://stackoverflow.com/questions/11907961/redirect-using-angularjs – Mikel Bitson Nov 05 '15 at 21:39
  • @MikelBitson is there a way to have the modal open when the page loads using Angular? Like redirect, and then show modal on page load? – hollyquinn Nov 05 '15 at 21:55
  • Yeah, that's what I was saying with the query string parameter. Should the modal ALWAYS open on the search page, or only when this redirect puts the user to the search page? Simply add an angularapp and controller to the page and open the modal in your controller. – Mikel Bitson Nov 05 '15 at 21:56
  • Yes it will always open on the search page. How do you open the modal in the controller? Currently I'm using a bootstrap modal it opens on button click. – hollyquinn Nov 05 '15 at 22:00
  • @MikelBitson would you like to offer an answer with some code? :) – hollyquinn Nov 05 '15 at 22:20
  • when loading your page .. call the function that handles the modal (that you usually call with ng-click on the button) it should have $uibModal.open({...}); – MayK Nov 05 '15 at 22:24
  • @MayK I have had no luck getting the uibModal to work. Everyone where I work is new to Angular, and none of us can get it to work, so I decided to use a bootstrap modal instead. – hollyquinn Nov 05 '15 at 22:35
  • I think I got it. I was able to load the modal on page load with javascript. Thanks. – hollyquinn Nov 05 '15 at 22:40

0 Answers0