错误./src/app/app.module.ts找不到模块

时间:2017-07-18 08:09:46

标签: angular2-routing router angular2-modules

我正在开发angular-cli。我遇到了以下错误。

min_row=3

我的 node_module中有 @ angular / router / src / router_module 这个库。缺少什么?

以下是必填文件。

app.module.ts

ERROR in ./src/app/app.module.ts
Module not found: Error: Can't resolve '@angular/router/src/router_module' in 
'E:\xampp\Angular-cli\Login\src\app'
@ ./src/app/app.module.ts 13:0-69
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts

router.component.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { AdminAccount } from './admin/admin.component';
import { LoginForm } from './login/login.component';
import { FileData } from './filedata/filedata.component';
import { ROUTER_PROVIDERS } from "@angular/router/src/router_module";
import { RouterModule, Routes, ROUTES } from "@angular/router";
import { Http, Response } from "@angular/http";
import { Route } from './router/router.component';

@NgModule(
{
imports: [RouterModule ,Route, BrowserModule, Http, Response, AdminAccount, LoginForm, FileData, Route],
declarations: [AppComponent],
providers: [ROUTER_PROVIDERS],
bootstrap: [AppComponent]
})
export class AppModule { }

app.component.ts

import { Component, OnInit } from '@angular/core';
import { RouterModule } from "@angular/router";
import { LoginForm } from "../login/login.component";
import { AdminAccount } from "../admin/admin.component";

 export const Route = RouterModule.forRoot(
[
{ path: '/', component: LoginForm },
{ path: '/admin', component: AdminAccount }
]);

如果需要更多文件,请告诉我。

1 个答案:

答案 0 :(得分:-1)

@Fahad Nasir这里 AdminAcount。

import { Component, OnInit } from '@angular/core';
import { Router } from "@angular/router";

@Component(
{
selector: "admin",
templateUrl: "./admin.component.html",
})

export class AdminAccount
{
adminUser = document.cookie.split("??")[0];
adminPass = document.cookie.split("??")[1];

constructor(public router: Router)
{
    if (document.cookie !== undefined)
    {
        if (this.adminUser == "admin" && this.adminPass == "admin")
        {
            console.log("Welcome!");
        }
        else
        {
            this.router.navigate(["Loginform"]);
            console.log("Redirect!");
        }
    }
    else
    {
        console.log("Error: Undefined Login!");
    }
}
}

Here Have a look