So I'm knew to AngularJS(1.6.4). I have a component that I would like to hide/show programmatically using the controller. Unfortunately, I don't understand how to grab hold of my component, and then set the ng-hide to false.
Right now, my controller looks like so with a service call. When the data returns, I would like to run my hide/show logic:
<div id="container" class="flex-container"><!-- flex container -->
<div class="box" id="redbox" class="flex-item"><!-- flex item -->
<input id="searchTermInput" class="search-input">
</div>
<div class="box" id="greenbox" class="flex-item"><!-- flex item -->
<button id="searchButton" class="search-button" (click)="runSearch($event)">
Search
</button>
</div>
<hr width="100%" class="divider-line" ng-hide="dividerHider">
<div class="flex-item search-results">
<ul class="heroes">
<li *ngFor="let result of searchResults">
<span class="badge">{{result.id}}</span> {{result.title}}
</li>
</ul>
</div>
</div>
.
import { Component } from '@angular/core';
import {SearchService} from "./search.service";
import {SearchResult} from "./search-result";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers: [SearchService]
})
export class AppComponent {
title = 'app';
searchResults: SearchResult[];
constructor(private searchResultService: SearchService) { }
runSearch(ev): void {
var q = 100;
this.searchResultService.getHeroesSlowly().then(searchResults => {
this.searchResults = searchResults;
alert("Hello! I am an alert box!!" + this.searchResults.length);
//Call hide component here
}
)
}
}
I've done my research on hiding things programmatically, but their code doesn't seem to use the controller very much at all. For example, in this response here
and here
AngularJS - ng-hide with different ng-controller
I'm totally at a loss as to where that code concerning "$scope" is supposed to go.
Any help is greatly appreciated.
EDIT: Solution
I ended up using this construct.
...
<hr width="100%" id="divider" class="divider-line" *ngIf="showDivider">
...
export class AppComponent {
showDivider = false;
runSearch(ev): void {
this.searchResultService.getHeroesSlowly().then(searchResults => {
this.showDivider = true;
}
)
}
}