2016-10-26 15 views
0

ng-clickディレクティブを使用してボタンをクリックすると、関数openAbout()が呼び出され、divを1つ表示し、その他はすべて非表示にします。このコードで動作しますが、5つではなく2つのステートメントを作成するには何がありますか?例えば、最初に表示され、他のすべてのものは隠されています。あなたはngShow/ngHideを使用する場合を除きおかげ1つの要素を表示し、JSで他の要素を非表示にする方法

<md-button id="about" ng-click="openAbout()"> 
    About Us 
</md-button> 


$scope.openAbout=function() { 
    document.getElementById("first").style.display = "block"; 
    document.getElementById("second").style.display = "none"; 
    document.getElementById("third").style.display = "none"; 
    document.getElementById("fourth").style.display = "none"; 
    document.getElementById("fifth").style.display = "none";  
}; 
+0

はい、私はそれはそれでは動作しませんアンギュラ – frontendgirl

答えて

1

あなたは

$scope.openAbout=function(){ 
    $(".divClass").hide(); // give all divs the same class 
    $("#first").show(); 
}; 

を意味する:https://scotch.io/tutorials/how-to-use-ngshow-and-nghide

+0

で働いている、私が試してみました。 – frontendgirl

+0

"それでうまくいかない"という意味は何ですか?コンソールのエラー? – mplungjan

+0

いいえ、要素を非表示にすることはありません。それらの要素はすべてページ上にあります。 – frontendgirl

関連する問題