Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: make structural directives guide generic #44895

Conversation

dario-piotrowicz
Copy link
Contributor

@dario-piotrowicz dario-piotrowicz commented Jan 29, 2022

tweak the current structural directives guide (currently mainly targeted
at the creation of custom structural directives) so that is more generic
and a point of reference for structural directives in general

this also includes the re-addition of the one-per-element section
removed in PR #40015

resolves #44786

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #44786

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

  • @AndrewKushnir 馃檪馃憤

  • Before & After:
    Before:
    Screenshot at 2022-01-29 21-24-14

    Screenshot at 2022-01-29 21-23-05

    After:
    Screenshot at 2022-01-29 21-24-45

    Screenshot at 2022-01-29 21-22-24

  • The "Improving template type checking for custom directives" section should be moved to a different guide, I figured I could keep things cleared by moving it away from the page in a follow-up PR

  • This partially undoes changes made in PR docs: rewrite structural directives聽#40015

@@ -110,15 +110,20 @@ <h2 id="ngFor">NgFor</h2>

<p class="code">&lt;div *ngFor="let hero of heroes; let i=index; let odd=odd; trackBy: trackById" [class.odd]="odd"&gt;</p>
<!--#docregion inside-ngfor -->
<div *ngFor="let hero of heroes; let i=index; let odd=odd; trackBy: trackById" [class.odd]="odd">
<div
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I split this and the one below because in the UI the lines were easily wrapped, this should marginally help

@@ -240,15 +240,12 @@ then uses this template repeatedly to create a new set of elements and bindings
in the list.
For more information about shorthand, see the [Structural Directives](guide/structural-directives#shorthand) guide.

{@a one-per-element}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this section isn't really explaining clearly the one-per-element topic, a section just for that has been added in the structural directives guide.


For more information about `NgFor` see the [NgForOf API reference](api/common/NgForOf).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this guide already talks about the NgFor in the previous sections, so putting here the link seems to me pretty unnecessary


<div class="alert is-helpful">

For the example application that this page describes, see the <live-example></live-example>.

</div>

For more information on Angular's built-in structural directives, such as `NgIf`, `NgForOf`, and `NgSwitch`, see [Built-in directives](guide/built-in-directives).
## What they are
Copy link
Contributor Author

Choose a reason for hiding this comment

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

may not be the best section name ever.... 馃槗

Copy link
Contributor

Choose a reason for hiding this comment

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

You could eliminate the need for this header by moving lines 13-15 to above the example.
Because that's the obvious place to see a description of the subject you're about to discuss further in the topic, it doesn't need a heading to introduce it.

Comment on lines 79 to 74
{@a one-per-element}
## One structural directive per element
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This section was removed in PR #40015 (which by the way is the PR that made this guide non-generic)

I am not a big fan of moving changes back and forth but I believe the way this was refactored really just lacks clarity and makes things much more difficult to understand.

I put back the section with one or two minor tweaks as I thought it was already well written, if we want I can rewrite this with my own words too.

@@ -295,12 +309,14 @@ The value of the property can be either a general type-narrowing function based
For example, consider the following structural directive that takes the result of a template expression as an input:

<code-example language="ts" header="IfLoadedDirective">
export type Loaded<T> = { type: 'loaded', data: T };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated this to use &lt; and &gt; since without them the type annotations are actually not displayed:
Screenshot at 2022-01-29 21-34-55

(PS: I also split the lines to help in readability)

Comment on lines 143 to 158
### Creating template fragments with `<ng-template>`

Angular's `<ng-template>` element defines a template that doesn't render anything by default.
With `<ng-template>`, you can render the content manually for full control over how the content displays.

If there is no structural directive and you wrap some elements in an `<ng-template>`, those elements disappear.
In the following example, Angular does not render the middle "Hip!" in the phrase "Hip! Hip! Hooray!" because of the surrounding `<ng-template>`.

<code-example path="structural-directives/src/app/app.component.html" header="src/app/app.component.html (template-tag)" region="template-tag"></code-example>

<div class="lightbox">
<img src='generated/images/guide/structural-directives/template-rendering.png' alt="template tag rendering">
</div>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this should sit in the structural directives guide, I changed this (see line 70 above) to a quick alert redirecting to the ng-template api docs (in which I also added a shortened alert with the example shown here)

@dario-piotrowicz dario-piotrowicz force-pushed the aio-general-structural-directives-guide branch from 1278b26 to a886017 Compare January 29, 2022 21:46
@dario-piotrowicz dario-piotrowicz marked this pull request as ready for review January 30, 2022 12:18
@pullapprove pullapprove bot requested a review from atscott January 30, 2022 12:18
@dario-piotrowicz
Copy link
Contributor Author

dario-piotrowicz commented Jan 30, 2022

I just noticed that I am applying the fix for: #40739

in that issue it is suggested to move the example to a doc region, my fixing it here shouldn't prevent that from being done afterwards anyways (maybe as a follow-up PR, as I mentioned in the PR's description the section should also be moved elsewhere, maybe both things can be done in the same PR)

(PS: I volunteer myself for that by the way 馃槃)

@ngbot ngbot bot added this to the Backlog milestone Jan 31, 2022
@AndrewKushnir AndrewKushnir self-requested a review January 31, 2022 18:34
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

Awesome work @dario-piotrowicz 馃憤

I've left a few comments, please let me know what you think.

Once the feedback is addressed, we'd need a docs team review of the content as well.

Thank you.

aio/content/guide/structural-directives.md Outdated Show resolved Hide resolved
aio/content/guide/structural-directives.md Outdated Show resolved Hide resolved
aio/content/guide/structural-directives.md Outdated Show resolved Hide resolved
aio/content/guide/structural-directives.md Outdated Show resolved Hide resolved
aio/content/guide/structural-directives.md Outdated Show resolved Hide resolved
aio/content/special-elements/core/ng-template.md Outdated Show resolved Hide resolved
@dario-piotrowicz
Copy link
Contributor Author

@AndrewKushnir thanks a lot for your awesome reviewing! 馃槏

(and sorry for making you put that many comments 馃檹 馃槗)

I've addressed your comments, please have another look 馃檪

aio/content/guide/structural-directives.md Outdated Show resolved Hide resolved
aio/content/guide/structural-directives.md Outdated Show resolved Hide resolved
aio/content/guide/structural-directives.md Outdated Show resolved Hide resolved
aio/content/guide/structural-directives.md Outdated Show resolved Hide resolved
aio/content/guide/structural-directives.md Outdated Show resolved Hide resolved
@atscott
Copy link
Contributor

atscott commented Feb 14, 2022

Added @TeriGlover for editing review.

@dario-piotrowicz
Copy link
Contributor Author

Thanks for the nice reviewing @atscott 馃檪, all addressed 馃憤

@dario-piotrowicz
Copy link
Contributor Author

Hi @TeriGlover, any change you could have a look at this PR? 馃檱 馃檹 馃檱

@dario-piotrowicz dario-piotrowicz force-pushed the aio-general-structural-directives-guide branch from 46800ff to fcda1d0 Compare March 29, 2022 22:34
@dario-piotrowicz dario-piotrowicz force-pushed the aio-general-structural-directives-guide branch 2 times, most recently from d3deed3 to 37d041b Compare April 11, 2022 18:38
@jessicajaniuk jessicajaniuk added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Apr 11, 2022
@AndrewKushnir
Copy link
Contributor

@bob-watson could you please help with the review for this PR from docs perspective (Andrew and myself verified that the context is correct from the technical perspective)? Thank you.

Copy link
Contributor

@bob-watson bob-watson left a comment

Choose a reason for hiding this comment

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

If the "what they are" heading really bugs you, I offered an alternative.
Other than that, it seems reasonable after a quick glance.


<div class="alert is-helpful">

For the example application that this page describes, see the <live-example></live-example>.

</div>

For more information on Angular's built-in structural directives, such as `NgIf`, `NgForOf`, and `NgSwitch`, see [Built-in directives](guide/built-in-directives).
## What they are
Copy link
Contributor

Choose a reason for hiding this comment

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

You could eliminate the need for this header by moving lines 13-15 to above the example.
Because that's the obvious place to see a description of the subject you're about to discuss further in the topic, it doesn't need a heading to introduce it.

tweak the current structural directives guide (currently mainly targeted
at the creation of custom structural directives) so that is more generic
and a point of reference for structural directives in general

this also includes the re-addition of the one-per-element section
removed in PR angular#40015

resolves angular#44786
@dario-piotrowicz dario-piotrowicz force-pushed the aio-general-structural-directives-guide branch from 37d041b to dc1641e Compare May 19, 2022 23:00
@AndrewKushnir AndrewKushnir added action: rerun CI at HEAD and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels May 20, 2022
@AndrewKushnir AndrewKushnir added the action: merge The PR is ready for merge by the caretaker label May 20, 2022
@ngbot
Copy link

ngbot bot commented May 20, 2022

I see that you just added the action: merge label, but the following checks are still failing:
聽聽聽聽failure status "pullapprove" is failing
聽聽聽聽pending 3 pending code reviews

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken main, please try rebasing to main and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@AndrewKushnir AndrewKushnir added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label May 20, 2022
@AndrewKushnir
Copy link
Contributor

Merge-assistance: the approvals got reset after a fixup commit. I've reviewed and approved it, so this PR is ready for merge.

@alxhub
Copy link
Member

alxhub commented May 23, 2022

This PR was merged into the repository by commit c8086b7.

@alxhub alxhub closed this in c8086b7 May 23, 2022
alxhub pushed a commit that referenced this pull request May 23, 2022
tweak the current structural directives guide (currently mainly targeted
at the creation of custom structural directives) so that is more generic
and a point of reference for structural directives in general

this also includes the re-addition of the one-per-element section
removed in PR #40015

resolves #44786

PR Close #44895
alxhub pushed a commit that referenced this pull request May 23, 2022
tweak the current structural directives guide (currently mainly targeted
at the creation of custom structural directives) so that is more generic
and a point of reference for structural directives in general

this also includes the re-addition of the one-per-element section
removed in PR #40015

resolves #44786

PR Close #44895
dario-piotrowicz added a commit to dario-piotrowicz/angular that referenced this pull request Jun 2, 2022
amend the aio glossary using as the structural-directives guide link's title the
outdated heading of that guide (changed in PR angular#44895)
alxhub pushed a commit that referenced this pull request Jun 3, 2022
)

amend the aio glossary using as the structural-directives guide link's title the
outdated heading of that guide (changed in PR #44895)

PR Close #46228
alxhub pushed a commit that referenced this pull request Jun 3, 2022
)

amend the aio glossary using as the structural-directives guide link's title the
outdated heading of that guide (changed in PR #44895)

PR Close #46228
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make the current "structural-directives" guide more generic
6 participants