Reputation: 278
I'm trying to use ng-container with NgTemplateOutlet (https://angular.io/docs/ts/latest/api/common/index/NgTemplateOutlet-directive.html)
<div *ngFor="let child of children; let i=index">
<ng-container *ngTemplateOutlet="inputTpl; { $implicit: child, index: i }"></ng-container>
</div>
Thie results in the error
Unexpected token {, expected identifier, keyword, or string at column 11 in [inputTpl; { $implicit: child, index: i }]
When I use 'context:' like in the docs, this leads to
Can't bind to 'ngTemplateOutletContext' since it isn't a known property of 'ng-container'
If I use a object declared in my ts file and set it instead of my Object, everything is working fine. Moreover this is also working fine:
<div *ngFor="let child of children; let i=index" class="form-group">
<template [ngTemplateOutlet]="inputTpl" [ngOutletContext]="{ $implicit: child, index: i }" />
</div>
Does anybody know, how I can use ng-container with *ngTemplateOutlet and ngTemplateOutletContext generated in the html?
Upvotes: 9
Views: 15403
Reputation: 167
you might have to import CommonModule
in the module declaring your current component.
Upvotes: 0
Reputation: 2682
Example for angular 5.
<ng-container [ngTemplateOutlet]="optionTemplate.template" [ngTemplateOutletContext]="{option:option}">
</ng-container>
<p-auto-complete property='searchText' [options]="options"(onChange)="select($event)">
<ng-template pOptionTemplate let-option="option">
<div>
//...
</div>
</ng-template>
</p-auto-complete>
Upvotes: 6
Reputation: 2404
call to the main template
<ng-template *ngTemplateOutlet="callMain; context: { $implicit: item }"></ng-template> // can use multiple places
main template
<ng-template #callMain let-item>
//use dynamic item object
</ng-template>
Upvotes: 0
Reputation: 1845
Did you try <ng-container>
with [ngTemplateOutletContext]
like this?
<ng-container
[ngTemplateOutlet]="inputTpl"
[ngTemplateOutletContext]="{ $implicit: child, index: i }"
>
</ng-container>
Upvotes: 7
Reputation: 3914
Maybe you should update your dependencies to 2.4?
"dependencies": {
"@angular/common": "~2.4.3",
"@angular/compiler": "~2.4.3",
"@angular/core": "~2.4.3",
"@angular/forms": "~2.4.3",
"@angular/http": "~2.4.3",
"@angular/platform-browser": "~2.4.3",
"@angular/platform-browser-dynamic": "~2.4.3",
"@angular/platform-server": "~2.4.3",
"@angular/router": "~3.4.3",
"@angularclass/conventions-loader": "^1.0.2",
"@angularclass/hmr": "~1.2.2",
"@angularclass/hmr-loader": "~3.0.2",
"core-js": "^2.4.1",
"http-server": "^0.9.0",
"ie-shim": "^0.1.0",
"jasmine-core": "^2.5.2",
"reflect-metadata": "^0.1.9",
"rxjs": "~5.0.2",
"zone.js": "~0.7.4"
},
Upvotes: 0