2

jrSwitchCases · GitHub

 1 year ago
source link: https://gist.github.com/jonrimmer/eaabd619e2edeaebed83b7bc68f33daf
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

jrSwitchCases · GitHub

Instantly share code, notes, and snippets.

jrSwitchCases

Thanks for sharing

nice! :)

There is one extraneous closing parenthesis at the end of line 28.

Can't wait for this feature to be addressed in Angular (angular/angular#14659), in the mean time, thanks for sharing!

Hi all,

I found an other, more complex, issue.

If you have a default in you switch, the element of your default directive will be instanciated and then destroyed right after.
This is caused by the fact that we have to wait for the input property to be passed to the directive before adding the new cases in
jonrimmer directive. But in angular case directive, the case is added directly in the constructor.

To fix this issue, you simply have to set this.ngSwitch._defaultUsed to true in the constructor and then set it to false in the ngOnInit. This will prevent ngSwitch from switching to default before the cases are added.

Note that this means that at initialization, there will be a moment where the switch will not render anything even tho you specified a default element.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK