Replace ng-include node with template?

前端 未结 7 999
感情败类
感情败类 2020-11-30 23:36

Kinda new to angular. Is it possible to replace the ng-include node with the contents of the included template? For example, with:

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 00:06

    Another alternative is to write your own simple replace/include directive e.g.

        .directive('myReplace', function () {
                   return {
                       replace: true,
                       restrict: 'A',
                       templateUrl: function (iElement, iAttrs) {
                           if (!iAttrs.myReplace) throw new Error("my-replace: template url must be provided");
                           return iAttrs.myReplace;
                       }
                   };
               });
    

    This would then be used as follows:

提交回复
热议问题