Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.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 在html中使用异步管道=>¿;行为主体还是可观察的?_Angular_Observable_Behaviorsubject - Fatal编程技术网

Angular 在html中使用异步管道=>¿;行为主体还是可观察的?

Angular 在html中使用异步管道=>¿;行为主体还是可观察的?,angular,observable,behaviorsubject,Angular,Observable,Behaviorsubject,我有一个疑问,我正在做的项目,我看到了: private _isReady$: BehaviorSubject<boolean> = new <boolean>(false); get IsReady$(): Observable<boolean> { return this._isReady$.asObservable(); } 为什么不将behaviorSubject定义为public,并在html中与异步管道一起直接使用它呢?将该行为主体作为可

我有一个疑问,我正在做的项目,我看到了:

private _isReady$: BehaviorSubject<boolean> = new <boolean>(false);
get IsReady$(): Observable<boolean> {
    return this._isReady$.asObservable();
}

为什么不将behaviorSubject定义为public,并在html中与异步管道一起直接使用它呢?将该行为主体作为可观察对象返回到html中使用它有什么区别/好处?

原因是
行为主体
\u isReady$
)private是只允许特定服务发出可观察对象(不允许其他组件或服务发出)


但是其他人只能使用可公开访问的可观察的
IsReady$

订阅
您是对的,非常感谢您的解释
{{ isReady$ | async}}