Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 2.2.3-默认情况下,服务和组件对象是否应解耦/隔离?_Angular - Fatal编程技术网

Angular 2.2.3-默认情况下,服务和组件对象是否应解耦/隔离?

Angular 2.2.3-默认情况下,服务和组件对象是否应解耦/隔离?,angular,Angular,我使用的是Angular 2.2.3。如果对象存储在服务中,并且通过getter从组件中的服务检索该对象,并将其设置为本地对象。如果对组件进行了更改,是否也会影响服务对象 我问的原因是在我的项目中,它确实做了上述工作,但我认为Angular 2的设计是为了使组件/服务相互隔离。因此,我们为什么使用RXJS来广播更改 以下是我的意思的一个例子: 我的服务包括: test: {name: string, test: boolean} = {name:'Peter',test:false}; getT

我使用的是Angular 2.2.3。如果对象存储在服务中,并且通过getter从组件中的服务检索该对象,并将其设置为本地对象。如果对组件进行了更改,是否也会影响服务对象

我问的原因是在我的项目中,它确实做了上述工作,但我认为Angular 2的设计是为了使组件/服务相互隔离。因此,我们为什么使用RXJS来广播更改

以下是我的意思的一个例子:

我的服务包括:

test: {name: string, test: boolean} = {name:'Peter',test:false};
getTest() {
    return this.test;
}
我的组件具有以下功能:

test() {
    let test: any = this.myService.getTest();
    test.name = 'John';
    test.test = true;
    console.log('Component Object',test, 'Service Component', this.myService.getTest());
  }
当在组件中执行上述功能时,Console将打印以下内容

Component Object Object {name: "John", test: true} Service Component Object {name: "John", test: true}

是的,我明白JavaScript就是这样。但我认为Angular 2已经解耦了。