Parser Error: Got interpolation ({{}}) where expression was expected
Asked Answered
G

7

32

I'm using ng-bootstrap as a substitute for ui-bootstrap in angular2.

My html is as follows:

<ul class="list-inline">
    <li class="tag" ngb-dropdown auto-close="outsideClick" 
        *ngFor="let item of ['Elastic Search','Database Theory','CVS'];
        let $index=index;" 
        [ngClass]="{'default-tag': $index==0, 'matched-tag': $index==1, 'unmatched-tag': $index==2 }">
         <a href ngb-dropdown-toggle id="desiredSkill{{$index}}">
             <i class="bi_interface-tick following"></i> {{item}} <i class="bi_interface-more tag-menu-icon"></i>
                            </a>
               <ul class="dropdown-menu tag-menu" ngb-dropdown-menu [aria-labelledby]="desiredSkill{{$index}}">
                     <li><a href>Follow Skill</a></li>
                     <li><a href>Related Jobs</a></li>
                </ul>
     </li>
  </ul>

But when I run my app I get following error:

main.browser.ts:25Error: Template parse errors: Parser Error: Got interpolation ({{}}) where expression was expected at column 12 in [desiredSkill{{$index}}] in JobDescription@174:77 (" ][aria-labelledby]="desiredSkill{{$index}}">

  • "): JobDescription@174:77 Parser Error: Unexpected token '{' at column 13 in [desiredSkill{{$index}}] in JobDescription@174:77 ("
    ][aria-labelledby]="desiredSkill{{$index}}">
  • "): JobDescription@174:77 Can't bind to 'aria-labelledby' since it isn't a known property of 'ul'. (" ][aria-labelledby]="desiredSkill{{$index}}">
  • "): JobDescription@174:77 Parser Error: Got interpolation ({{}}) where expression was expected at column 12 in [desiredSkill{{$index}}] in JobDescription@174:77 ("
                    <div class="row">
                      <div class="col-lg-4 col-xs-4" [ERROR ->]*ngFor="let i of [0,1,3]">
                        <img src="http://ecx.images-amazon.com/images/I/81VFU9"):
    

    JobDescription@215:49 Parser Error: Unexpected token '{' at column 13 in [desiredSkill{{$index}}] in JobDescription@174:77 ("

                    <div class="row">
                      <div class="col-lg-4 col-xs-4" [ERROR ->]*ngFor="let i of [0,1,3]">
                        <img src="http://ecx.images-amazon.com/images/I/81VFU9"):
    

    JobDescription@215:49 Parser Error: Got interpolation ({{}}) where expression was expected at column 12 in [desiredSkill{{$index}}] in JobDescription@174:77 (" ERROR ->="main.applyJob()">Apply for job ERROR ->="main.applyJob()">Apply for job ][hidden]="!ifNotApplied">Applied ][hidden]="!ifNotApplied">Applied ][hidden]="!ifNotUploaded">Upload CV ][hidden]="!ifNotUploaded">Upload CV Have questions about this job?

    [ERROR ->] Have questions about this job? [ERROR ->]
  • Giacobo answered 23/10, 2016 at 13:7 Comment(0)
    R
    47

    You can't use interpolation inside standard property binding. There should be an expression.

    Seems it should be:

    [attr.aria-labelledby]="'desiredSkill' + $index"
    

    or

    attr.aria-labelledby="desiredSkill{{$index}}"
    
    Randle answered 23/10, 2016 at 13:34 Comment(0)
    W
    13

    Usually this error occurs when we are trying to implement both Interpolation and Property data binding on the same html property.

    Example:

    Wrong implementation

    [disabled]= {{isDisabled}}
    

    Correct implementation

    disabled= {{isDisabled}}
    

    Note: remove the square bracket from the html element property

    Wahoo answered 4/10, 2018 at 3:31 Comment(1)
    This didn't work for me, it resulted in error TS2322: Type 'string' is not assignable to type 'boolean', even though the property isDisabled was defined as a boolean. I was able to solve both that and the OP's error with: [disabled]="isDisabled"Andreeandrei
    C
    3

    Use this

      <button class="btn btn-primary" title="Edit" (click)="showEditModal(record.id)"><i class="fa fa-edit"></i></button>
    
    Charlatanry answered 22/1, 2019 at 7:27 Comment(0)
    M
    2

    I think you forgot to declare index of ngFor

    *ngFor="let item of ['Elastic Search','Database Theory','CVS'];let $index=index" ...
    

    also use,

    [attr.aria-labelledby]="desiredSkill{{$index}}"
    
    Mycosis answered 23/10, 2016 at 13:17 Comment(3)
    can you try with [attr.aria-labelledby]="desiredSkill{{$index}}"?Mycosis
    That is not a solution if I'll add it to attr then ngb-bootstrap will ignore its value and it will be just added the attribute to the elementGiacobo
    Oh I see. try other answer provided by yurzui.Mycosis
    S
    1

    If you want pass only $index value

    [attr.aria-labelledby]=" ' ' + $index"
    
    Sebastiansebastiano answered 19/6, 2019 at 12:33 Comment(0)
    S
    0

    In link tags use like this

    Use this

    <a  class="custom-badge status-blue" [routerLink]="'/hospital/doctorleave/'+item.Id]">Manage Leave</a> 
    

    Instead of

    <a  class="custom-badge status-blue" [routerLink]="'/hospital/doctorleave/{{item.Id}}']">Manage Leave</a> 
    
    Samoyed answered 14/6, 2019 at 7:47 Comment(0)
    C
    0

    For me changing this

    <img [src]="{{picture.name}}" [alt]="picture. caption"/>

    To this:

    <img src="{{picture.name}}" alt="picture.caption"/>

    Solved the problem. The problem was this -> [] around the properties i.e src and alt in the html/template file.

    Cohosh answered 6/5, 2023 at 18:40 Comment(0)

    © 2022 - 2024 — McMap. All rights reserved.