0
在rxjs中我想改變複雜對象中的屬性但改變沒有別的東西。如何更改可觀察的複雜對象?
例如:
我有用戶等級:
class User {
constructor(
public name: string,
public role: string
) { }
}
我的服務:
@Injectable()
export class AuthService {
user: BehaviorSubject<User>;
constructor() {
this.user = new BehaviorSubject(
new User('wizardnet', 'admin')
);
}
setRole(role) {
// change ONLY the Role property of this.user ???????
// subscribe then clone the object and then call next() ??
}
}
如何做到這一點?
完美!我錯過了。價值:) –
@ShlomiLevi美麗的'BehaviorSubject' :) – CozyAzure