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!
NgModel expects the bound element to have a value property, which div s don't have. That's why you get the No value accessor error. I don't know if the input event is supported on all browsers for contenteditable . You could always bind to some keyboard event instead.
AngularJS ng-show Directive The ng-show directive shows the specified HTML element if the expression evaluates to true, otherwise the HTML element is hidden.
For a single btn, it's ok to use ng-click or onclick in the ng-app . There is no difference between the two functions. For effective team work, you,d better to have an account with each other. In Angular apps, ng-click is recommended.
ng-if is better in this regard. Using it in place of ng-show will prevent the heavy content from being rendered in the first place if the expression is false. However, its strength is also its weakness, because if the user hides the chart and then shows it again, the content is rendered from scratch each time.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With