2016-11-11 26 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/angular-2-dynamic-tabs-with-user-click-selected-components/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

いいえ、* ngの代わりに[hidden]を使用できます。 –

-3

それがリダイレクトされますFIRSTPAGE負荷が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

Angular 2はどこですか? –

関連する問題