Anukrati Khare
Anukrati Khare

Reputation: 11

ANGULARJS :How to send radio button value from controller to another?

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?

Upvotes: 0

Views: 117

Answers (1)

joshbang
joshbang

Reputation: 181

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

Upvotes: 0

Related Questions