Using Jquery inside AngularJS directive good or bad idea?

前端 未结 3 1919
萌比男神i
萌比男神i 2021-02-07 22:00

Below you can see my code for the directive.

My question is: \" Can i use jquery with directives? Is that a good idea? If not why? \"

o         


        
3条回答
  •  青春惊慌失措
    2021-02-07 22:19

    You should not be using jquery as Angular itself has a lighter version for it known as jqlite.

    More documentation on JQLITE

    So your directive should look like:

    outsource.directive('dedicated', function(){
    
        return {
           restrict: 'E',
           link: function(scope, element, attribute){
    
                 var elem = angular.element(document.querySelector('#klik'))
                 angular.element(elem).triggerHandler('click');
    
           },
    
           replace: true,
           templateUrl: 'src/app/components/views/dedicated-prices.html'
        };
    });
    

提交回复
热议问题