I have service like folowing:
@Injectable({
providedIn: 'root'
})
export class BoxContainerService {
private boxBehaviour: BehaviorSubject<any[]> = new BehaviorSubject<any[]>([]);
boxes$ = this.boxBehaviour.asObservable();
addBox(b: any) {
if (!b) return;
this.boxBehaviour.next([...this.boxBehaviour.value, layer]);
}
}
And I am injection in multiple components like following.
@Component({
selector: 'my-list',
templateUrl: './my-list.component.html'
})
export class MyListComponent implements OnInit, OnDestroy {
constructor(private service: BoxContainerService) {
}
ngonInit(){
}
}
But I want to get new instance of BoxContainerService every route change. When I refresh the page, new instace is created. But if route from MyList_page to B_page and againg MyList_page, the boxes$ count is increasing. I want recreate the service instance during the module. Because I will import the module in another module.