简体   繁体   中英

angular2 template, how to pass arguments other than variables

In angular2, given this code

<div id="{{window.id}}_body" class="session_body hidden">
    <div class="tab" *ngFor="let bookmark of window.bookmarks; let i = index;" id="{{window.id}}_{{i}}_bookmark">
        <bookmark [id]="window.id"+'_'+"i"+'_bookmark' [bookmark]="bookmark.url"></bookmark>
    </div>
</div>

It fails because when I try to pass the variable [id]

<bookmark [id]="window.id"+'_'+"i"+'_bookmark' [bookmark]="bookmark.url">

I am not passing a simple variable, but a string that uses variables.

Can it be done? Or I should pass the variables "window.id" and "i" separately and then re-construct the id from this later on (which is what I'd like to avoid), like

<bookmark [id]="window.id" [index]="i" [bookmark]="bookmark.url">

It works.

You just got entangled in your simple/double quotes :

<bookmark [id]="window.id+'_'+i+'_bookmark'">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM