0

I am newbie of angularjs. I have a jquery click function i.e,

Here jQuery code:-

$('.nav li').click(function(){
  $('#sidebar').hide();
});

Now,I just implement the above jquery function in angularjs.

Somethings like:

var ele = angular.element('.nav li');
ele.click=function(){
  var sidebarEle=angular.element('#sidebar');
  sidebarEle.hide();
}
3
  • so what is the problem ? Commented May 5, 2016 at 5:45
  • 1
    what actually you want to do ?? what you have tried, share your code ... Commented May 5, 2016 at 5:46
  • i updated my question. i think now clear. Commented May 5, 2016 at 6:13

2 Answers 2

1

I think you should try this

<div ng-app="MyApp" class="container">
        <div ng-controller="ctrl">
            <p id="sidebar">My Name is Vipin</p>
            @*<table id="entry-grid" datatable="" dt-options="dtOptions" dt-columns="dtColumns" class="table table-hover"></table>*@

            <button type="button" ng-click="hide()" class="nav li">CLik</button>
        </div>
    </div>



 var app = angular.module('MyApp', []).controller('ctrl', function ($scope) {
                var ele = angular.element(document.querySelector('.nav'));

                $scope.hide = function () {
                    angular.element(document.querySelector('#sidebar')).css('display', 'none');
                }
                    //var sidebarEle = angular.element('#sidebar');

            })

it will help

Sign up to request clarification or add additional context in comments.

Comments

0

You need to create a controller containing function to be called on click, i.e. your click event handler.

$scope.OnClick = function(){
  $scope.showSidebar = false;
}

In HTML -

<nav ng-show="showSidebar"></nav>
<input type="button" ng-click="OnClick"/>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.