jquery - Angularjs show-hide -


im trying re-write of application using angularjs.. far i've used jquery , made use of .show , .hide example:

example.html

<div>     <ul>         <li>             <div class="home-heading">home</div>         </li>         <li>             <div class="products-heading">products</div>         </li>             <li>             <div class="about-heading">about us</div>         </li>         <li>             <div class="contact-heading">contact us</div>         </li>     </ul> </div>  <div class="home">     welcome home </div>  <div class="products">     welcome products </div>  <div class="about">     welcome </div>  <div class="contact">     welcome contact </div> 

show.js

$('.home-heading').on('click', function() {         $(".home").show();     $(".products").hide();     $(".about").hide();     $(".contact").hide(); });  $('.products-heading').on('click', function() {         $(".home").hide();     $(".products").show();     $(".about").hide();     $(".contact").hide(); });  $('.about-heading').on('click', function() {         $(".home").hide();     $(".products").hide();     $(".about").show();     $(".contact").hide(); });   $('.contact-heading').on('click', function() {         $(".home").hide();     $(".products").hide();     $(".about").hide();     $(".contact").show(); }); 

adding angular example.html page:

<div ng-controller="testcontroller">     <ul>         <li>             <div class="home-heading" ng-click="showhome()">home</div>         </li>         <li>             <div class="products-heading" ng-click="showproducts()">products</div>         </li>             <li>             <div class="about-heading" ng-click="showaboutus()">about us</div>         </li>         <li>             <div class="contact-heading" ng-click="showcontact()">contact us</div>         </li>     </ul> </div>  <div class="home">     welcome home </div>  <div class="products">     welcome home </div>  <div class="about">     welcome home </div>  <div class="contact">     welcome home </div> 

testcontroller.js:

require(['app'], function(app) { app.controller("testcontroller", function($scope) {           $scope.showhome = function()     {         alert('showhome responding');     };      $scope.showproducts = function()     {         alert('showproducts responding');     };  }); }); 

the correct alert messages showing on corresponding click, cannot corresponding div show/hide.

you can still use of same in angular. can this:

markup

<div class="home" ng-show="showhomecontainer">     welcome home </div> 

js

$scope.showhomecontainer = false;  $scope.showhome = function(){     $scope.showhomecontainer = true; }; 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -