Angular 角度2,当我在项目中使用路由时,在控制台窗口中显示错误

Angular 角度2,当我在项目中使用路由时,在控制台窗口中显示错误,angular,routing,Angular,Routing,异常:未捕获(承诺中):错误:./e类e中的错误-内联模板:9:6原因:对象未订阅 错误:./e类e中的错误-内联模板:9:6原因:对象未订阅 在ViewWrappedError.ZoneAwareError()中 //aap.component.ts import { Component } from '@angular/core'; // import { LocalStorageService } from 'angular-2-local-storage'; @Component({

异常:未捕获(承诺中):错误:./e类e中的错误-内联模板:9:6原因:对象未订阅 错误:./e类e中的错误-内联模板:9:6原因:对象未订阅 在ViewWrappedError.ZoneAwareError()中

//aap.component.ts

import { Component } from '@angular/core';
// import { LocalStorageService } from 'angular-2-local-storage';

@Component({
    moduleId: module.id,
    selector: 'my-app',
    template: `
            <div class="container">
                <div class="punjab-vehicle-wrapper">
                    <div class="punjab-vehicle">
                        <a routerLink="/province" routerLinkActive="active" > Province Vehicle Verification </a>
                        <a routerLink="/capital"> Capital Vehicle Verification </a>
                    </div>  
                </div>
            </div>
            <router-outlet></router-outlet>
    `
})

export class AppComponent{

}

我不知道哪个文件出错,

可能是您无法在app.module.ts中导入新组件

试着修改你的代码
  • app.component.ts

    import { Component } from '@angular/core';
    // import { LocalStorageService } from 'angular-2-local-storage';
    
    @Component({
        moduleId: module.id,
        selector: 'my-app',
        template: `
                <div class="container">
                    <div class="punjab-vehicle-wrapper">
                        <div class="punjab-vehicle">
                            <a routerLink="/province" routerLinkActive="active" > Province Vehicle Verification </a>
                            <a routerLink="/capital"> Capital Vehicle Verification </a>
                        </div>  
                    </div>
                </div>
                <router-outlet></router-outlet>
        `
    })
    
    export class AppComponent{
    
    }
    
    
    从'@angular/core'导入{Component};
    @组成部分({
    选择器:“我的应用程序”,
    模板:
    })
    导出类AppComponent{}
    

  • app-routing.module.ts

    
    从“@angular/core”导入{NgModule};
    从'@angular/router'导入{Routes,RouterModule};
    从“./AppComponent.component”导入{AppComponent};
    常数批准:路由=[{
    路径:“”,
    重定向到:'/main',
    路径匹配:“已满”
    }, {
    路径:'主',
    组件:AppComponent
    }];
    @NGD模块({
    导入:[RouterModule.forRoot(批准)],
    导出:[路由模块]
    })
    导出类AppRoutingModule{}
    

  • app.module.ts

    
    从“@angular/platform browser”导入{BrowserModule};
    从“@angular/core”导入{NgModule};
    从'@angular/forms'导入{FormsModule,ReactiveFormsModule};
    从'@angular/http'导入{HttpModule};
    从“./AppComponent.component”导入{AppComponent};
    从“./app routing.module”导入{AppRoutingModule};
    @NGD模块({
    进口:[
    浏览器模块,
    FormsModule,
    反应形式模块,
    HttpModule,
    批准模块
    ],
    声明:[
    应用组件
    ],
    提供者:[],
    引导:[AppComponent]
    })
    导出类AppModule{}
    

    希望这是工作
给我们看一些代码,很难调试空气。。。