| 2235 | } |
| 2236 | |
| 2237 | @Directive({ |
| 2238 | selector: 'dynamic-vp', |
| 2239 | standalone: false, |
| 2240 | }) |
| 2241 | class DynamicViewport { |
| 2242 | private injector: Injector; |
| 2243 | constructor(private vc: ViewContainerRef) { |
| 2244 | const myService = new MyService(); |
| 2245 | myService.greeting = 'dynamic greet'; |
| 2246 | |
| 2247 | this.injector = Injector.create({ |
| 2248 | providers: [{provide: MyService, useValue: myService}], |
| 2249 | parent: vc.injector, |
| 2250 | }); |
| 2251 | } |
| 2252 | |
| 2253 | create(): ComponentRef<ChildCompUsingService> { |
| 2254 | return this.vc.createComponent(ChildCompUsingService, { |
| 2255 | index: this.vc.length, |
| 2256 | injector: this.injector, |
| 2257 | }); |
| 2258 | } |
| 2259 | |
| 2260 | insert(viewRef: ViewRef, index?: number): ViewRef { |
| 2261 | return this.vc.insert(viewRef, index); |
| 2262 | } |
| 2263 | |
| 2264 | move(viewRef: ViewRef, currentIndex: number): ViewRef { |
| 2265 | return this.vc.move(viewRef, currentIndex); |
| 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | @Directive({ |
| 2270 | selector: '[my-dir]', |
nothing calls this directly
no test coverage detected
searching dependent graphs…