【发布时间】:2017-10-12 06:29:08
【问题描述】:
我想将表单值传递给要在 Observable 中使用的服务。在将服务注入组件时如何传递名称值?该服务一直使用环境变量,但我是通过一个表单来自定义名称。谢谢!
class Component {
constructor(private myService: MYService){}
customer: Customer = new Customer();
updateService(customerForm: NgForm){ ..get it to service
customerForm.value.name; }
class MyService {
openId: Observable<OpenId>;
constructor(private http: Http, private router: Router){
\\ How do I get this.name from component?
this.openId = this.getOpenID(this.name);
}
private getOpenId(name: string): Observable<OpenId>{
return this.http.get(`${name}`).map(res => res.json()).publishlast().refCount();
}
【问题讨论】:
标签: angular rxjs observable