-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Conversation
…placed on will be removed if transcluded content exists. In other case the content will be saved and used as content by default.
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
CLAs look good, thanks! |
Hi, would it be possible for you to:
I am not very happy in changing the existing (already complex) transclude behavior, but with a good reason I can change my mind |
Use case: Just imagine we have a case when we need to use a majority of identic elements throughout the project, for example buttons with the same text, look and behavior. Also there will be elements with the same behaviour but different look and content (e.g. text). angular.module('transcludeDefaultContentExample', [])
.directive('myButton', function(){
return {
restrict: 'E',
transclude: true,
scope: true,
template: '<button style="cursor: pointer;">' +
'<ng-transclude></ng-transclude>'
'</button>'
};
}); Now, having the current For example: <my-button><b style="color: red;">Warning</b></my-button>
<my-button><b style="color: red;">Warning</b></my-button>
<my-button><b style="color: red;">Warning</b></my-button>
<my-button><b style="color: red;">Warning</b></my-button> And only in case of elements with the different look and content we will type in another content. <my-button><b style="color: green;">Ok</b></my-button> The update I offer will let us avoid this multiple and useless copying & pasting. We will be able to set the ‘default’ look just once (as content of ng-transclude element) and change it only for the element that needs to look different. angular.module('transcludeDefaultContentExample', [])
.directive('myButton', function(){
return {
restrict: 'E',
transclude: true,
scope: true,
template: '<button style="cursor: pointer;">' +
'<ng-transclude>' +
'<b style="color: red;">Warning</b>' +
'</ng-transclude>' +
'</button>'
};
}); <my-button></my-button>
<my-button></my-button>
<my-button></my-button>
<my-button></my-button>
<my-button><b style="color: green;">Ok</b></my-button> |
Hi, @lgalfaso
|
related issue #7195 |
Hey! |
I like this feature a lot. You've got my vote! |
It does sound useful. Features for 1.5.x are closed, but we can put it on the table for 1.6 (it needs a rebase, though). |
# Conflicts: # src/ng/directive/ngTransclude.js
@Narretz, done. Could you please move it to 1.6.x milestone? |
+1 |
# Conflicts: # src/ng/directive/ngTransclude.js
…ontent exists Closes angular#11839
…ontent exists Closes angular#11839
Existing content of the element that this directive is placed on will be removed only if transcluded content exists. In other case the content will be saved and used as content by default.
It will be useful if you need to use default content in directive's template and replace it only in some directive instances.
Example:
Directive template:
Directive instance with modified content:
Which would generate:
Directive instance without modified content:
Which would generate: