2017-07-08 42 views
1

嗨社區我有一個Plunker,我已經實現了這個流程:角4刷新節僅

更新Plunker:我解決,但頭組件被稱爲每次,我必須把我的頭組件中的每個HTML有沒有更好的方法來做到這一點?

  1. 登錄
  2. 國家的顯示列表(在上面的用戶信息)
  3. 點擊一下的國家和節目細節的一個(問題是在這裏)
  4. 回到列表

我只需要刷新國家/地區列表的一部分,但在我的plunker中,您可以看到整個頁面正在刷新,我想將用戶信息保留在頂部(靜態)。

我幾乎沒有經驗。 非常感謝!

@Component({ 
selector : 'login', 
template: ` 
<input type="text" value="james"> 
<input type="password" value="123"> 
<button (click)="logIn()">Login</button> 
` 
}) 
class LoginComponent { 
constructor(private route: ActivatedRoute, 
      private router: Router) { } 

    logIn() { 
     //LOGIN LOGIC 
     this.router.navigate(['/base']); 
    } 
} 

回答

0

router-outlet顯示路線的內容。 這意味着你必須把router-outlet所以wone通過你的路線導航的影響上述用戶模板代碼...

<label>User: Mr. James</label> 
    <label>Role: Administrator</label> 
    <hr> 
<router-outlet> 
+0

我已經在根組件標籤。把路由器插座沒有顯示國家列表。 – Diego

0

我終於設法解決了這個問題!我找到了這樣做的方式,但這不是正確的方法。這裏是解決方案:http://plnkr.co/edit/pNoGFP6fva4SYmcspoOj?p=preview

我用子組件在所述路由配置和改變導航完成的方式:其中

this.router.navigate(['/base', { outlets: { mod : ['countrydetail', country_id ] } } ]); 

  • /鹼是由來成分,其中,所述導航正在開始。
  • mod是出口名稱(app.routing兒童)
  • countrydetail子組件名稱
  • COUNTRY_ID:參數