0

I have two radio buttons redirecting to same application.jsp page but I just want to add/remove few fields on that application based on button that is clicked.

For example- if btn 1 is clicked i want to see NAME and EMAIL fields on the application page but if btn2 is clicked I want to see DOB along with NAME, EMAIL

Question: I want to store button value in controller so that I can use ng-show/ng-hide to display fields based on button click.

Problem: This button uses controller Ctrl 1 whereas the application page where it is redirecting to uses Ctrl 2.

  <input type="radio" name="test" id="r1" ng-model= "test" value="false" 
  onclick="window.location.href='/application'">
  <label for="btn1">create app 1</label>

  <input type="radio" name="test" id="r2" ng-model="test" value="true" 
  onclick="window.location.href='/application'">
  <label for="btn2">create app 2</label>

Please let me know the solution for retaining scope value in different controller. OR if there is any better solution?

3
  • Have you tried doing in it with Parent-Child Controller? stackoverflow.com/questions/21453697/… Commented May 4, 2018 at 17:43
  • Can't you use $rootscope for value to travel across controllers? Commented May 4, 2018 at 17:55
  • @JonathanAnctil In my case, Controllers are not nested Commented May 5, 2018 at 1:08

1 Answer 1

0

It sounds more like it is a problem that can be handled with $state. Whatever data you need on the next page can be added to and then taken from $stateParams($state.params). Hope I helped point you in the right direction!

I always try to stay away from using $rootScope for little things. Thats just me though

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

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.