Reputation: 1077
This was asked in an interview.
Requirement is to create a custom pipe that would return a shortened text suffixed by a 'Read more' link for a text if it has more than a certain number of characters, lets say 10 characters.
If clicked on the 'Read more' link, the entire original text should be displayed suffixed by a 'Read less' link. If clicked on the 'Read less' link, again the shortened text should be displayed suffixed by a 'Read more' link. Thus, 'Read more' and 'Read less' links and short and original text should toggle on click of the links.
This entire functionality is to be implemented by a pipe only. Is event handling possible in a pipe? How we can handle events for the clicks on the links in the pipe?
Upvotes: 0
Views: 541
Reputation: 1454
I think the interviewer doesn't know the actual use of a pipe. Basically a pipe
shouldn't
handle like these
kinds
of
complex
operations
. A pipe should handle some basic operations like
The best choice would be using a Shared Component
. He can use this to communicate events between the components.
Upvotes: 1