Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
86
rated 0 times [  90] [ 4]  / answers: 1 / hits: 137581  / 10 Years ago, sat, april 12, 2014, 12:00:00

I am trying just to display a div when user press a button, seems to be easy, but after spent a lot of time I am getting really crazy with this. My code is



My fiddle: http://jsfiddle.net/jmhostalet/4WK7R/1/



<div ng-app>
<div ng-controller=MyCtrl>
<div><button id=mybutton ng-click=showAlert()>Click me</button></div>
<div>Value: {{myvalue}}</div>
<div><div ng-show=myvalue class=hideByDefault>Here I am</div></div>
</div>
</div>


and my controller



function MyCtrl($scope) {

$scope.myvalue = false;

$scope.showAlert = function(){
$scope.myvalue = true;
};
}


Thank you!


More From » angularjs

 Answers
11

Just get rid of the display: none; from your CSS. AngularJS is in control of showing/hiding that div.



If you want to hide it by default, just set the value of scope.myvalue to false initially - which you're already doing.


[#71490] Thursday, April 10, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
parker

Total Points: 259
Total Questions: 109
Total Answers: 97

Location: Zambia
Member since Thu, Jun 25, 2020
4 Years ago
;