Avoid using extra DOM nodes when using nginclude

后端 未结 5 704
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-31 10:23

I\'m struggling to wrap my mind around how to have an ng-include not use an extra DOM element as I\'m building an angular app from a plain-HTML demo. I\'m working with pretty sl

5条回答
  •  有刺的猬
    2021-01-31 10:49

    You can create a custom directive, linking to the template with the templateUrl property, and setting replace to true:

    app.directive('myDirective', function() {
      return {
        templateUrl: 'url/to/template',
        replace: true,
        link: function(scope, elem, attrs) {
    
        }
      }
    });
    

    That would include the template as-is, without any wrapper element, without any wrapper scope.

提交回复
热议问题