How to load a script using custom angular directive?

后端 未结 1 785
傲寒
傲寒 2021-01-16 07:41

I am trying to load a script in my custom angular directive. Right now, it is simply adding script tag in DOM but it is not loading it.

angular.module(\'my         


        
1条回答
  •  北荒
    北荒 (楼主)
    2021-01-16 08:36

    Something seems a little wrong here, but if you really wanted to do this you could just append a script tag to your directive's element:

    app.directive('loadDirective', function() {
      return {
        restrict: 'E',
        link: function($scope, $el) {
    
          var script = document.createElement('script');
          script.src = '//cdnjs.cloudflare.com/ajax/libs/emojione/1.3.0/lib/js/emojione.min.js'
          $el.append(script);
        }
      }
    });
    

    Plunk

    0 讨论(0)
提交回复
热议问题