Angular study notes (Material Dialog)

When learning overlay and portal, has not figure out where to play the role viewContainerRef

Here to talk about the ins and outs

When we create an overlay, while creating a portal outlet

 

 When we want to append content, internal real-time call attachComponentPortal method of DomPortalOutlet

 

This time will be based portal <- Incoming component portal, not a portal outlet Oh, do not be confused.

When there viewContainerRef decide how to create a component.

If you have to call viewContainerRef create component method, then will insert component to container rendering. Then cut and paste operation by dom to portal outlet (body).

If not directly by the component factory create component and then view into the global appRef inside. This time the component does not append to dom anywhere. 

然后 cut and paste to portal outlet.

When app.tick, all appRef.views will detech change. 

 

2 What's the difference? 

 

Does not explain much in the portal's documentation ... just saying what different logic tree and the tree view of it. 

Instead, the documentation explains dialog

 

From the source point of view it is.

After using viewContainerRef, detech change is based on the timing of viewContainerRef

The situation put appRef, timing is app.tick detech change each time the trigger.

 

 appRef.attachView the view put in an array.

 

 Call detech change in tick of time.

 

As injector actually quite confused, because attachComponentPortal injector is based on the injector component portal, there is no relationship between the Han Ah with viewContainerRef. Why dialog documentation says it has a relationship

 

Read the source code will be found, dialog creation injector portal using userInjector || rootInjector, the so-called userInjector is viewContainerRef.injector.

This truth is out slightly.

 

Guess you like

Origin www.cnblogs.com/keatkeat/p/11809680.html