Show/Hide onclick - angularjs

Qwerty

This is what i'm trying to achieve.

section1 will be hidden at page load. When user clicks on Advanced, section1 should show & section2 should hide. On clicking Basic, the opposite should happen. Nothing happens when I click any of the anchor tags now. Where am i going wrong.

<div class="container" ng-init="advstatus=true">
  <a href="#" onclick="advstatus=true">Basic</a>
  <br/>
  <a href="#" onclick="advstatus=false">Advanced</a>

  <div class="section1" ng-hide="advstatus">
    ///...
  </div>
  <section ng-show="advstatus" class="section2">
   ///...
  </section>
</div>
Omri Aharon

In AngularJS you need to use ng-click instead of onclick.

Also, ng-init isn't supposed to be used unless you're in ng-repeat, which you are not (take a look at the Docs).

You should set up the variable in your controller:

<div ng-app ng-controller="myCtrl" class="container" >
  <a href="javascript:void(0);" ng-click="advstatus=true">Basic</a>
  <br/>
  <a href="javascript:void(0);" ng-click="advstatus=false">Advanced</a>

  <div class="section1" ng-show="!advstatus">
    Section 1
  </div>
  <section ng-show="advstatus" class="section2">
   Section 2
  </section>
</div>

Controller:

function myCtrl($scope) {
    $scope.advstatus = true;
}

JS Fiddle

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

onclick to show <p><h1><iframe> , function showHide(shID)

From Dev

AngularJS - {{$index}} within onclick

From Dev

AngularJs Render div onclick

From Dev

AngularJS pass Object onClick

From Dev

AngularJs Render div onclick

From Dev

Show/Hide onclick - angularjs

From Dev

ShowHide multiple li > blockquote #Quote

From Dev

Angularjs Skype URI "onclick" issue

From Dev

Angularjs directive and now onclick is slow

From Dev

toggle contents onclick button in angularjs

From Dev

AngularJS Get Filtered Scope onClick

From Dev

Addition of two numbers in angularJS onclick

From Dev

Weird bug on my javascript showhide code

From Dev

onclick how to toggle the limitTo value using AngularJS?

From Dev

How to append div element onclick in angularjs

From Dev

AngularJS nested ng-repeat onclick

From Dev

angularjs scope variable change onclick for conditional div

From Dev

AngularJS - Adding an onClick event to a Button via a Directive

From Dev

How to call a AngularJS controller using onclick event

From Dev

Open kendo menu onClick using angularjs

From Dev

How to append div element onclick in angularjs

From Dev

Reset the scope using an onclick event with AngularJS

From Dev

AngularJS Filter (onclick) with Multiple Filter Values

From Dev

ng-click not firing in AngularJS while onclick does

From Dev

Why I can't pass angularJS parameter on onClick html event?

From Dev

Thymeleaf value send angularJS ng-onclick method

From Dev

AngularJS and HTML: Escaping quotes inside a variable for an onclick function

From Dev

How to send the input text box value to angularjs onclick on the text box?

From Dev

Angularjs data from json, onclick , show corresponding data to the right

Related Related

HotTag

Archive