如何将布尔值Subject的值初始化为false?

时间:2018-06-26 15:49:19

标签: angular typescript rxjs

我有一个主题:private _hasErrro: Subject<boolean>,我想初始化为假,我该怎么做?

1 个答案:

答案 0 :(得分:0)

您可以在创建主题之后按以下方式对其进行初始化:

                <li class="nav-item">
                <a class="nav-link collapsed" href="#submenu3" data-toggle="collapse" data-target="#submenu3">Site</a>
                <div class="collapse" id="submenu3" aria-expanded="false">
                    <ul class="flex-column pl-2 nav">
                        <li class="nav-item"><a class="nav-link @ManageAdminPages.SiteCompanyAdminClass(ViewContext)" asp-page="./SiteCompany">Company</a></li>
                        <li class="nav-item">
                            <a class="nav-link collapsed py-1" href="#submenu3sub1" data-toggle="collapse" data-target="#submenu3sub1">General</a>
                            <div class="collapse" id="submenu3sub1" aria-expanded="false">
                                <ul class="flex-column nav pl-4">
                                    <li class="nav-item">
                                        <a class="nav-link @ManageAdminPages.SiteGeneralManageAdminClass(ViewContext)" asp-page="./SiteGeneralManage">
                                            Manage
                                        </a>
                                    </li>
                                    <li class="nav-item">
                                        <a class="nav-link @ManageAdminPages.SiteGemeralLoginAdminClass(ViewContext)" asp-page="./SiteGeneralLogin">
                                            Login
                                        </a>
                                    </li>
                                    <li class="nav-item">
                                        <a class="nav-link @ManageAdminPages.SiteGeneralRegisterAdminClass(ViewContext)" asp-page="./SiteGeneralRegister">
                                            Register
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </li>

但是,如果要在创建初始值时提供它,则需要使用BehaviorSubject。如果它是_hasError.next(false); ,则可以按如下所示对其进行初始化:

BehaviorSubject