2016-06-14 6 views
1

おはよう。私の問題は、RegisterComponentのRoutelinkがLogInComponentのページにルーティングしないボタンで、理由を理解できません。角度はいかなる誤りによっても起こらない。コンポーネントが別のコンポーネントのページにルーティングされない

import { Component } from '../Vendor/@angular/core'; 
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '../Vendor/@angular/router-deprecated'; 

import { RegistrationComponent } from './Registration' 

@Component({ 
    selector: 'logIn', 
    templateUrl: './Views/LogInView.html', 
    providers: [ROUTER_PROVIDERS], 
    directives: [ROUTER_DIRECTIVES, RegistrationComponent] 
}) 

@RouteConfig([ 
    { 
     path: '/registration', 
     name: 'registration', 
     component: RegistrationComponent 
    } 
]) 

export class LogInComponent { 
    constructor() { console.log("1");} 
} 

ビュー:

<from> 
    <div> 
     <div> 
      <input name="userName" placeholder="логин"> 
     </div> 
     <div> 
      <input name="password1" placeholder="******"> 
     </div> 
     <div> 
      <button>Войти</button> 
     </div> 
     <div> 
      <button [routerLink]="['Registration']">Регистрация</button> 
     </div> 
    </div> 
</from> 
whick RegistrationComponentべきルートに、

> <from> 
>  <div class=".col-lg-"> 
>   <div> 
>    <input name="userName" placeholder="логин"> 
>   </div> 
>   <div> 
>    <input name="password1" placeholder="******"> 
>   </div> 
>   <div> 
>    <input name="password2" placeholder="******"> 
>   </div> 
>   <div> 
>    <button>Зарегестрироваться</button> 
>   </div> 
>   <div> 
>    <button [routerLink]="['LogIn']">Вход</button> 
>   </div> 
>  </div> </from> 

そして、これはLogInComponentです: これはRouteComponentあり、それはビューです:

import { Component } from '../Vendor/@angular/core'; 
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '../Vendor/@angular/router-deprecated'; 

import { LogInComponent } from './LogIn'; 

@Component({ 
    selector: 'reg', 
    templateUrl: './Views/RegView.html', 
    providers: [ROUTER_PROVIDERS], 
    directives: [ROUTER_DIRECTIVES, LogInComponent], 
    // styleUrls: ['../../Styles/bootstrap/bootstrap.css'] 
}) 

@RouteConfig([ 
    { 
     path: '/logIn', 
     name: 'LogIn', 
     component: LogInComponent 
    } 
]) 

export class RegistrationComponent { 

} 

ビュー

これは主なApplicationComponentです。それは(私は用語が右であることを願っています)RegistrationComponentを呼び出す必要があります。

import { Component } from '../Vendor/@angular/core'; 

import { RegistrationComponent } from './Registration'; 


@Component({ 
    selector: 'app', 
    templateUrl: './Views/appview.html', 
    directives: [ RegistrationComponent ] 
}) 


export class AppComponent { 

} 
view: 
<reg></reg> 

答えて

0

私はブーツを除いてどこでもproviders: [ROUTER_PROVIDERS]を削除しました。なぜそれが助けられたのかはわかりませんが、すべてが今働いています。

+1

ルートで1回だけ 'ROUTER_PROVIDERS'を提供する必要があります。それ以外の場合、各コンポーネントは別のルータインスタンスを取得します。 –

+0

@GünterZöchbauer、もう一度感謝します。あなたは私をたくさん助けました。 – Amelina

関連する問題