AngularJS : transcluding multiple sub elements in a single Angular directive

后端 未结 3 1562
长情又很酷
长情又很酷 2021-02-01 14:27

I am Fairly new to Angular but have been reading quite a lot. I was reading about ng-transclude at http://docs.angularjs.org/guide/directive#creating-custom-directi

3条回答
  •  北恋
    北恋 (楼主)
    2021-02-01 14:55

    Starting Angular 1.5, it's now possible to create multiple slots. Instead of transclude:true, you provide an object with the mappings of each slot:

    https://docs.angularjs.org/api/ng/directive/ngTransclude

    angular.module('multiSlotTranscludeExample', [])
     .directive('pane', function(){
        return {
          restrict: 'E',
          transclude: {
            'title': '?pane-title',
            'body': 'pane-body',
            'footer': '?pane-footer'
          },
          template: '
    ' + '
    Fallback Title
    ' + '
    ' + '' + '
    ' }; })

提交回复
热议问题