我想根据索引更改属性的值,但页面保持空白
<div *ngIf="detallePost">
<div id="accordion" class="container">
<h2>{{ detallePost.title | uppercase }}</h2>
<div>
<span>id del Post : </span>{{detallePost.id}}
</div>
<div>
<span> {{ detallePost.body }}</span>
</div>
<ul>
<li *ngFor="let comment of commentsPost; let i = index">
<!-- Cabecera -->
<div class="card">
<div class="card-header" id="heading{{i}}">
<h5 class="mb-0">
<button class="btn btn-link"
data-toggle="collapse"
data-target="#collapse{{i}}"
aria-expanded="true"
aria-controls="collapse{{i}}">
{{comment.email}}
</button>
</h5>
</div>
<!--Final Cabecera-->
<!--Texto mostrado-->
<div id="collapse{{i}}"
class="collapse"
aria-labelledby="heading{{i}}"
data-parent="#accordion">
<div class="card-body">
{{comment.body}}
</div>
</div>
<!--Final Texto mostrado-->
</div>
</li>
</ul>
<button (click)="goBack()" class="btn btn-primary">Volver</button>
</div>
</div>
控制台给出的错误是:
Uncaught Error: Template parse errors:
Can't bind to 'target' since it isn't a known property of 'button'. ("
<button class="btn btn-link"
data-toggle="collapse"
[ERROR ->]data-target="#collapse{{i}}"
aria-expanded="true"
aria-controls="collapse{{i}}">
"): ng:///AppModule/DetallePostComponent.html@17:9
Can't bind to 'aria-controls' since it isn't a known property of 'button'. ("
data-target="#collapse{{i}}"
aria-expanded="true"
[ERROR ->]aria-controls="collapse{{i}}">
{{comment.email}}
</button>
"): ng:///AppModule/DetallePostComponent.html@19:9
Can't bind to 'aria-labelledby' since it isn't a known property of 'div'. ("
<div id="collapse{{i}}"
class="collapse"
[ERROR ->]aria-labelledby="heading{{i}}"
data-parent="#accordion">
<div class="card-body">
"): ng:///AppModule/DetallePostComponent.html@28:7
at syntaxError (compiler.js:485)
at TemplateParser.parse (compiler.js:24668)
at JitCompiler._parseTemplate (compiler.js:34621)
at JitCompiler._compileTemplate (compiler.js:34596)
at eval (compiler.js:34497)
at Set.forEach (<anonymous>)
at JitCompiler._compileComponents (compiler.js:34497)
at eval (compiler.js:34367)
at Object.then (compiler.js:474)
at JitCompiler._compileModuleAndComponents (compiler.js:34
我要修改的属性是:
id="heading{{i}}
data-target="#collapse{{i}}"
aria-controls="collapse{{i}}">
id="collapse{{i}}"
aria-labelledby="heading{{i}}"
因为不希望它们重复,所以我已经验证了它{{i}}
有值0,1,2...等。
Angular 区分属性和属性。通常,当您在 Angular 模板中的标签上放置属性时,假设它是原生 HTML 属性、模板“所有者”组件的属性或指令。如果你不能将它与任何一个相关联,它就会失败。
那么如何添加不是属性的属性,例如
data-*
?如下:也就是
attr.
在前面加a,向angular表示它们是纯属性。