0
'use strict';
angular.module('simpleLiveApp'
.directive('cellar2Sidebar', ['$location', function () {
return {
templateUrl: './js/app/directives/sidebar/cellar2Sidebar.html',
restrict: 'E',
replace: true } }]);

I am working on a project and i want on the Directive above to add this JQuery code:

$( document ).ready(function() {
    $(".navbar-toggle").click(function(){
            $(".fa").toggleClass("fa-indent fa-outdent");
        });
});
4
  • 1
    don't use jQuery with angularjs; directives already use jQLite Commented Mar 26, 2018 at 14:39
  • take a look at stackoverflow.com/a/30616120/2801860 Commented Mar 26, 2018 at 14:43
  • this code won't run. angular.module('simpleLiveApp' <-- missing ) here Commented Mar 26, 2018 at 14:45
  • That snippet of jQuery code does not translate well to a directive. Instead describe what you want the cellar2Sidebar component to do. Implement it by using the ng-click directive and the ng-class directive in the HTML of the component. For more information, see “Thinking in AngularJS” if I have a jQuery background. Commented Mar 26, 2018 at 17:05

1 Answer 1

0

Angular has a builtin service called $document. it is a lite version of jQuery called jQLite.

which contains .ready https://docs.angularjs.org/api/ng/function/angular.element

or if you have a new version of angular/ want to support one (deprecated, use angular.element(callback) instead of angular.element(document).ready(callback))

from the documentation...

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.