I'm new to AngularJS and am trying to hide a div when a button is clicked. What I'm doing works fine until I put the button in the div I'm trying to hide (the button is using a different controller). The button works as expected when taken out of the controller so I assume it's an issue with scope. Any help would be appreciated.
<form action="" name="signUpForm" class="heroForm" >
<div ng-hide="signUpB">
<span id="signUpFormA">
<input required type="email" />
<input required type="password"/>
<span ng-controller="checkEmailCtrl">
<input type="button" ng-click="signUpB=true">
</span>
</span>
</div>
<div ng-show="signUpB">
<span id="signUpFormB">
<input required type="text">
<input required type="text">
<input type="submit">
<span>
</div>
</form>
Yes, you are setting
signUpB=true
on the scope ofcheckEmailCtrl
. You can do something like this:By wrapping the
signUpB
in an object, thesignUpB.value=true
statement will look up thesignUpB
object in the outer scope, and set it'svalue
property to true, no modification will be made oncheckEmailCtrl
's scope.