AngularJS - add HTML element to dom in directive without jQuery

前端 未结 4 1507
逝去的感伤
逝去的感伤 2021-01-31 02:35

I have an AngularJS directive in which I want to add a svg tag to the current element of the directive. Right now I do this with the help of jQuery

link: functio         


        
4条回答
  •  清歌不尽
    2021-01-31 03:25

    In angularJS, you can use angular.element which is the lite version of jQuery. You can do pretty much everything with it, so you don't need to include jQuery.

    So basically, you can rewrite your code to something like this:

    link: function (scope, iElement, iAttrs) {
      var svgTag = angular.element('');
      angular.element(svgTag).appendTo(iElement[0]);
      //...
    }
    

提交回复
热议问题