angular2实例化服务

时间:2016-11-14 20:35:31

标签: angular angular2-forms angular2-services

我从我的组件中调用这样的服务:

import { MissionService } from './modal.service';

我在构造函数中注入它:

model: any = {};
constructor(private modalService: NgbModal,
            private missionService: MissionService) {}
open(content) {  
    this.model = this.missionService.getCompany();
...
}

当我使用表单修改this.model时,this.missionService.getCompany()也会发生变化。 我想修改this.model而不更改对象this.missionService.getCompany()

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:

this.model = JSON.parse(JSON.stringify(this.missionService.getCompany()));