Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat(ngTransclude & $compile): fix treatment of unfilled optional slots #13431

Merged

Conversation

petebacondarwin
Copy link
Contributor

Closes #13426

@petebacondarwin
Copy link
Contributor Author

@PascalPrecht - hey look at this!

@0x-r4bbit
Copy link
Contributor

@petebacondarwin awesome! Does this also keep the original contents of the DOM where we transclude into?

E.g.

<span ng-transclude="fooSlot">
This is default DOM and going to be replaced if `fooSlot` is defined, if not this stays here
</span>

@petebacondarwin
Copy link
Contributor Author

Yep! That is the second commit in the PR.

@0x-r4bbit
Copy link
Contributor

Argh. I just've just read the commit messages instead of reading the code haha. Awesome! Thanks for the work!

@petebacondarwin
Copy link
Contributor Author

if (slotTranscludeFn) {
return slotTranscludeFn(scope, cloneAttachFn, transcludeControllers, futureParentElement, scopeToChild);
}
if (isUndefined(slotTranscludeFn)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about just else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to differentiate between null and undefined. I will add a comment to clarify.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I just noticed there's no difference in test behavior.

@Narretz
Copy link
Contributor

Narretz commented Dec 2, 2015

feat($compile): expose transclusion $$slotson the$transclude`

Isn't the commit message a bit contradictory? It's called a feature but $$slots indicates a private API.

And a question, is it possible to keep the content with the default behavior (no slots, transclude is true or content)? Since people have requested something similar for the default ngTransclude: #11839
I think we could extend the 'content' value to make it optional by adding ? and applying the same behavior.

@petebacondarwin
Copy link
Contributor Author

We could make $$slots -> $slots.

@petebacondarwin
Copy link
Contributor Author

Regarding default content for the default transclusion, perhaps we could special case "" in the transclude map:

transclude: {
  'required': 'requiredSlot',
  'optional': '?optionalSlot',
  '': '?' // this would make the default transclusion optional too...
}

and if you wanted optional default transclusion only then you would put:

transclude: { '': '?' }

@Narretz
Copy link
Contributor

Narretz commented Dec 2, 2015

Then we should also document $slots, I guess.

For default transchlusion. Okay, I forgot you can have default transclusion and slots. The proposed API for that looks a bit silly, but it's probably okay. But we can also decide on that after 1.5

@petebacondarwin
Copy link
Contributor Author

Hmm it is a bit awkward to make the default transclusion optional. I think we should punt that feature to post-1.5.0

@petebacondarwin petebacondarwin force-pushed the default-optional-slots branch 2 times, most recently from 5a5808a to c063544 Compare December 4, 2015 13:58
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@googlebot googlebot added cla: no and removed cla: yes labels Dec 4, 2015
@Narretz
Copy link
Contributor

Narretz commented Dec 4, 2015

Looks like the last commit caused some doc e2e tests to fail. :o Other than that, feel free to merge. We can tweak it after the fact.

…ional slot

Previously the contents of the `ngTransclude` element would always be emptied,
even if there was no transclusion to replace it.
Now, optional slots that have not been filled with content will not cause
the `ngTransclude` contents to be emptied.

Closes angular#13426
@petebacondarwin petebacondarwin merged commit e94b37e into angular:master Dec 4, 2015
@petebacondarwin petebacondarwin deleted the default-optional-slots branch November 24, 2016 09:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants