你好,我想拆分一个从db行得到的字符串。字符串是我使用的标记。我将它们作为文本导入到数据库行中。
例如,字符串是(#Hello,#hi,#hellothere )
我想像这样拆分标签,将每个单词用作一个按钮
<ion-row class="item-tags" *ngIf="item.tags?.length>0">
<ion-col class="tag-wrapper">
<span class="item-tag">
<ion-note>{{item.tags}}</ion-note>
</span>
</ion-col>
</ion-row>.ts函数
export class UserPage implements OnInit {
usersFlows:any =[];
tagsArray: any;
constructor(){}
usersFlowsSet() {//
this.offset = 0;
this.userData.usersFlow().pipe(
map((data:any) => {
if (data.success) {
this.usersFlows = data.userFlows;
this.tagsArray = this.usersFlows.tags.replace(/#/g,'').split(', ')
}
})
).subscribe()
}有什么帮助吗?
发布于 2020-08-22 18:17:01
和我想像这样拆分标记,将每个单词用作一个按钮
既然您想这样做,为什么不拆分控制器文件中的标记。
.split函数在您的html模板中不起作用。
this.tagsArray = this.item.tags.replace(/#/g,'').split(', ')然后在你的模板里面
<span class="item-tag" *ngFor="let tag of tagsArray">
<ion-button>{{tag}}</ion-button>
</span>https://stackoverflow.com/questions/63534740
复制相似问题