angular - 解析器错误 : Got interpolation ({{}}) where expression was expected

标签 angular angular-ui-bootstrap dropdown

我在 angular2 中使用 ng-bootstrap 替代 ui-bootstrap。

我的html如下:

<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>

但是当我运行我的应用程序时,出现以下错误:

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 ->]
  • 最佳答案

    您不能在标准属性绑定(bind)中使用插值。应该有一个表达式。

    似乎应该是:

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

    attr.aria-labelledby="desiredSkill{{$index}}"
    

    关于angular - 解析器错误 : Got interpolation ({{}}) where expression was expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40203279/

    相关文章:

    css - matRipple 的背景颜色

    css - Bootstrap 中的网格系统

    angularjs - Angular ui 轮播绑定(bind)重复调用

    angularjs - 如何更改在 ng-bind-html 中呈现的有效 HTML 标签?

    cakephp - 如何通过在 CakePHP 3 中组合/拥有两个字段来创建键值对(显示字段)?

    google-sheets - 如何反转下拉框 - Google 表格

    javascript - 如何更改 Angular Material 上 mat-icon 的大小?

    javascript - Angular 9 : How show with a HttpInterceptor the stacktrace of a request?

    angular - 清除按钮未重置 Angular 6 下拉列表中的选定值

    Angular 4 - 为 Facebook 动态更新元标签(打开图)