2016-11-11 55 views
-2

我試圖創建一個頁面的網站,這將默認加載1.component.html。當用戶點擊下一個按鈕時,它會加載2.component.html。同樣,如果用戶當前位於2.component.html並單擊後退按鈕,則會加載1.component.html。路由不是必需的。如何顯示/隱藏子組件

+0

我只是想確認一下,因爲你標記你的問題用'angularjs'和'angular2',你用什麼Angular版本來實現它? – Michael

+0

http://stackoverflow.com/questions/35578083/what-is-the-equivalent-of-ngshow-and-nghide-in-angular2/35578093#35578093或更高級的方案http://stackoverflow.com/questions/36325212 /角-2-動態突片與 - 用戶點擊選擇組件/ 36325468#36325468 –

回答

1

聽起來像任何標籤控制。

基本上你需要一個變量,而每次點擊改變它的狀態:

let status = 1; 

function onclick1(){ 
    this.status = 1; 
} 

function onclick2(){ 
    this.status = 2; 
} 

<button (click)="onclick1()">page1</button> 
<button (click)="onclick2()">page2</button> 
<div *ngIf="status==1">page1</div> 
<div *ngIf="status==2">page2</div> 
+0

我也想被保持在頁分離等1.component.html,....因爲我期待很多內容,所以它會提供更好的分離。 –

+0

你可以把一個組件元素這些div內 – Avi

+0

好答案,而不是* ngIf我們可以使用[隱藏] ... ALSE哪裏 –

-3

當將重定向第一頁負載component.html

//javascript code 
<script type = "text/javascript"> 
window.onload = function() 
{ 
alert("ohk"); 
document.getElementById("fom_id").action = "1.component.html";} 
</script> 

'**************Below code to redirect on another page******************* 
'**************Add this code on component.html file ******************* 

<script type="text/javascript"> 
//call this function on net button onclick event. 
function validate() 
{ 
alert("ohk"); 
var activeid = document.activeElement.id; 
    if (activeid == "next") 
    { 
     document.getElementById("form_id").action = 2.component.html  document.getElementById("form_id").submit(); 
    } 
} 
</script> 

//Add this same code for 2.component.html 
//redirect it to 1.component.html 
+0

年代角2參與? –