Angular: расширение службы с несколькими детьми - PullRequest
1 голос
/ 27 июня 2019

Расширение службы из нескольких дочерних элементов создает новые экземпляры служб.Я хочу иметь возможность расширять службу, и если данные изменяются от одного дочернего элемента, они также должны быть доступны от другого дочернего элемента.

Я попытался создать службу.Я создал два модуля, которые расширяют сервис.

@Injectable({
    providedIn: 'root'
})
export class BaseService {
    //Api stuff going on here
    constructor(){

    }
}

@Injectable({
    providedIn: 'root'
})
export class AuthService extends BaseService {
    //Login stuff going on there
    constructor(){
        super()
    }
}

export class LoginPage extends AuthService {
    //Handles login
    constructor(){
        super()
    }
}

@Injectable({
    providedIn: 'root'
})
export class UserService extends AuthService {
    //User stuff going on here
    constructor(){
        super()
    }
}

export class ProfilePage extends UserService {
    //Handles user stuff
    constructor(){
        super()
    }
}

//So LoginPage and UserService are both extending AuthService. For example
//setting a token from LoginPage ->AuthService should make the token available //in the UserService. But how it is now is that it creates multiple instances //of AuthService. Is this even possible to accomplish?

Я хочу знать, возможно ли это.Я знаю основной способ введения услуг, но это намного круче и практичнее.

...