だから私は k新規の角度 JS(1.6.4)です。私はコントローラを使用してプログラムで表示/非表示にしたいコンポーネントがあります。残念ながら、私は自分のコンポーネントをつかんで、ng-hideをfalseに設定する方法を理解していません。角度:コントローラからのコンポーネントを非表示
現在、私のコントローラは、サービスコールのように見えます。データが返ってくると、hide/showロジックを実行したいと思います:
<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
}
)
}
}
私はプログラム的に物事を隠すことに私の研究を行ってきたが、そのコードは非常にすべてのコントローラを使用していないようです。例えば、ここに
、ここ
AngularJS - ng-hide with different ng-controller
この応答では、私は「$スコープ」に関するそのコードが行くことになっている場所へと損失で完全です。
ご協力いただきまして誠にありがとうございます。
EDIT:ソリューション
私はこの構築体を使い終わった。
...
<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;
}
)
}
}
あなたのコードとテンプレートは、角度2+の構文を使用しています。 'ng-hide'ディレクティブはAngularJS(Angular 1.X)です。スコープと 'ng-hide 'はAngular 2+の一部ではありません。 – georgeawg
コードは '@ angular/core'をインポートします。 AngularJS 1.6.4ではなく、Angular 2+です。 – georgeawg
質問がフレーズであるので、これは重複していません。「コントローラからプログラム的に」隠す方法を尋ねるからです。リンクされた質問は答えません。 –