This article is a mirror article of machine translation, please click here to jump to the original article.

View: 15614|Reply: 0

[Angular] Angular 9 series (2) dynamic component transmission parameters

[Copy link]
Posted on 6/2/2020 2:57:07 PM | | | |
Review of the previous section

Angular 9 Series (1) Dynamically Loaded Components
https://www.itsvse.com/thread-9238-1-1.html

Angular 9 series (2) dynamic component transmission parameters
https://www.itsvse.com/thread-9245-1-1.html

Angular 9 series (3) subscribes to dynamic component events
https://www.itsvse.com/thread-9246-1-1.html

Angular 9 Series (IV) Custom Pipe pipelines
https://www.itsvse.com/thread-9248-1-1.html

Angular 9 Series (V) formats the amount currency format
https://www.itsvse.com/thread-9249-1-1.html


This article explains how to pass parameters to a dynamically created component.

Modal1Component and Modal2Component components are components that we dynamically create in the main interface, and if both components have the same input parameter, for example, name, we can define an interface.

Create an interface via the angular-cli command.

ng g interface IModalParameter

The code is as follows:


We will inherit the Modal1Component and Modal2Component components from the IModalParameter interface.



If our component does not add @Input() name: string; attributes, components will report errors, and the interface acts as a constraint.

At the same time, we edit the index.component.ts file, modify the onClick method, and the code is as follows:




(End)




Previous:.net/c# to get the current method name, parameter name
Next:Angular 9 series (3) subscribes to dynamic component events
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com