En mi página Stock tengo varios campos con un título llamado Title 1 .
¡Si hago un console.log estoy en mi primera página!
ngOnInit() { this.currentPortfolio = this.shrd.getData('currentPortfolio'); this.subPage = 'stocks'; this.sectionTitle = ""; this.pageTitle = "Options"; for (var i = 0; i < this.optionsDropdownFilters.length; i++) { this.issuers.actionsGrouped[this.optionsDropdownFilters[i]] = []; } console.log("First page => Tile 1 : " + JSON.stringify(this.subPage = 'stocks')); this.initiate(); } Ahora, hago clic en el botón Search en mi página Stock ... Quiero cambiar Title1 a Title2 .
Si hago un console.log, estoy en mi segunda página
launchSearchSelected(t) { this.searched = true; this.dateNotValid = false; this.dateDoesntExist = false; if (this.search.equityDate.length == 0) { this.dateDoesntExist = true } if (t == 'A' && this.search.equityOptionCode > 0 && this.search.equityDate.length > 0) { this.launchSearchResult(t, this.search.equityOptionCode, this.search.equityDate); } else if (t == 'I' && this.search.indexOptionCode.length > 0 && this.search.indexDate.length > 0) { this.launchSearchResult(t, this.search.indexOptionCode, this.search.indexDate); } console.log("Second Page => Title 2 " + JSON.stringify(this.searched = true)); }En mi HTML, no entiendo cómo puedo cambiar de un título a otro con el booleano.
<ng-container *ngIf="subPage === 'stocks' "> <div class="breadcrumb d-flex justify-content-between"> <h1>Title 1 </h1> </div> </ng-container>Es difícil saber cuál es la mejor manera de proceder sin más información, pero si solo desea cambiar el título en función de la variable this.subPage que tenga el valor " stocks " o no (como parece que lo está intentando), entonces puede hacer esto:
<ng-container> <div class="breadcrumb d-flex justify-content-between"> <h1 *ngIf="subPage == 'stocks'">Title 1</h1> <h1 *ngIf="subPage != 'stocks'">Title 2</h1> </div> </ng-container>tengo la solución:
<ng-container *ngIf="subPage === 'stocks' "> <ng-container *ngIf="spinners.search === true "> <div class="breadcrumb d-flex justify-content-between"> <h1>Title 1 </h1> </div> </ng-container> </ng-container> <ng-container *ngIf="subPage === 'stocks' "> <ng-container *ngIf="spinners.search === false "> <div class="breadcrumb d-flex justify-content-between"> <h1>Title 2 </h1> <button (click)="goBack()" class="btn btn-primary"> Back </button> </div> </ng-container> </ng-container>