我有一项服务,其中包含有关成员的信息。其中一个变量是团队字符串。
在我的组件中,我调用service方法将信息放入变量中,然后在组件中显示它。
我想填补变量"团队"在我的组件中,在服务中有一个唯一的团队列表。这应该考虑到写作(所以我会使用toUpperCase())。
我的服务:
import { Injectable } from '@angular/core';
@Injectable()
export class UserinfoService
{
//methods or services
getMembers()
{
return [
{
imageUrl: "../assets/images/filler.jpg",
firstName: "filler",
lastName: "filler",
team: "TEAM A",
number: "+123456798",
bio: "Lorem ipsum dolor sit amet,...",
isActive: true
},
{
imageUrl: "../assets/images/filler.jpg",
firstName: "filler",
lastName: "filler",
team: "TEam A",
number: "+123456798",
bio: "Lorem ipsum dolor sit amet,...",
isActive: false
},
{
imageUrl: "../assets/images/filler.jpg",
firstName: "filler",
lastName: "filler",
team: "TEAM B",
number: "+123456798",
bio: "Lorem ipsum dolor sit amet,...",
isActive: true
},
];
}
//constructor
constructor()
{
}
}
我的组件:
import { Component, OnInit } from '@angular/core';
import { UserinfoService } from '../services/userinfo.service';
@Component({
selector: 'app-teammembers',
templateUrl: './teammembers.component.html',
styleUrls: ['./teammembers.component.css']
})
export class TeammembersComponent implements OnInit
{
//props
teammembers: any[];
teams:any[];
constructor(userinfoService: UserinfoService)
{
//getData
this.teammembers = userinfoService.getMembers();
}
ngOnInit() {
}
}
答案 0 :(得分:1)
使用ES6,您可以在一行中实现此目的。以下是一个例子:
{{1}}