Dre*_*led 6 angular2-template angular
我有一个自定义angular2管道,它UserInfo使用服务将uid(字符串)转换为对象.
@Pipe({name: 'userInfo'})
export class UserInfoPipe implements PipeTransform {
constructor(public _userService: UserService) {
}
transform(uid:string) : any {
/*let users = this._userService.users.filter((u)=> {
return u.uid==uid;
});
if(users.length==1) return users[0];
return null;*/
return {"Name":"hans","Age":13};
}
}
Run Code Online (Sandbox Code Playgroud)
在我的组件中,我有一个绑定:
<Label row="4" text="Author: {{event?.author | userInfo | .Name}}" class="small-spacing"></Label>
Run Code Online (Sandbox Code Playgroud)
event?.author返回UID,在通过管道后userInfo我有一个对象.但是如何访问该对象的属性?有没有语法?.Name不起作用.
Dre*_*led 11
我发现了那个
(event?.author | userInfo).Name
Run Code Online (Sandbox Code Playgroud)
完全符合我的要求:它显示Name管道返回的对象的属性.
| 归档时间: |
|
| 查看次数: |
2213 次 |
| 最近记录: |