Angular: 使用 ng-repeat 和 ng-attr-id 动态设置 Id
Angular: Dynamically Setting the Id with ng-repeat and ng-attr-id
我正在尝试使用我的 ng-repeat 中使用的值设置锚标记的 ID。 {{channel}} 应该包含一个带有频道号的字符串。 {{channel}} 作为锚标记内的文本显示正常,但是对于 id,id 是空的,有人知道我如何正确实现它吗?
<li ng-repeat="channel in vm.channels">
<a ui-sref="channel({channel:channel, event: null})" ng-attr-id="{{channel}}" ui-sref-active="active">{{managedContent 'channel'}} \{{channel}}</a>
</li>
尝试:
ng-attr-id="{{ '' + channel }}"
或者简单地说:
id="{{ channel }}"
<div class="accordion" [attr.id]="'accordionTwo_' + i" *ngFor=" let i = index; let message of messages">
<button class="btn btn-info pull-right" data-toggle="collapse" [attr.data-parent]="'#accordionTwo_' + i" [attr.href]="'#collapseTwo_' + i"> Details </button>
<div [attr.id]="'collapseTwo_' + i" class="panel-collapse collapse in">
<h1>Expanded body</h1>
</div>
</div>
为*ngFor accordion 尝试上面的代码。
我正在尝试使用我的 ng-repeat 中使用的值设置锚标记的 ID。 {{channel}} 应该包含一个带有频道号的字符串。 {{channel}} 作为锚标记内的文本显示正常,但是对于 id,id 是空的,有人知道我如何正确实现它吗?
<li ng-repeat="channel in vm.channels">
<a ui-sref="channel({channel:channel, event: null})" ng-attr-id="{{channel}}" ui-sref-active="active">{{managedContent 'channel'}} \{{channel}}</a>
</li>
尝试:
ng-attr-id="{{ '' + channel }}"
或者简单地说:
id="{{ channel }}"
<div class="accordion" [attr.id]="'accordionTwo_' + i" *ngFor=" let i = index; let message of messages">
<button class="btn btn-info pull-right" data-toggle="collapse" [attr.data-parent]="'#accordionTwo_' + i" [attr.href]="'#collapseTwo_' + i"> Details </button>
<div [attr.id]="'collapseTwo_' + i" class="panel-collapse collapse in">
<h1>Expanded body</h1>
</div>
</div>
为*ngFor accordion 尝试上面的代码。