【问题标题】:Angular2 Routing error/missing componentAngular2路由错误/缺少组件
【发布时间】:2016-04-30 21:05:55
【问题描述】:

链接到不带模块的完整项目:https://www.dropbox.com/s/eaesfz4wvixusn5/EbayClone.zip?dl=0

我正在尝试添加一个名为“LogInPage”的网页,仅用于测试目的。 运行 npm start 后,我​​收到此错误,基本上说我应该将“LogInPage”文件添加到 nodes_modules 文件夹。在我这样做之后,我得到另一个错误,说缺少“异步”。我不确定我的路由是否正确,因为我尝试导入“登录组件”,但它说它从节点模块中丢失。

尝试加载网页时出现错误的屏幕截图: enter image description here

App.component.ts 代码

import {Component} from 'angular2/core';
import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router';
import {LogInComponent} from 'angular2/LogInPage';

@Component({
 selector: 'LogInPageSelector',
 template: `
 <h1>{{title}}</h1>
 <nav>
 <a [routerLink]="['LogIn']">Log in</a>
</nav>
 <router-outlet></router-outlet>
 `,
 styleUrls: ['app/app.component.css'],
 directives: [ROUTER_DIRECTIVES],

})
@RouteConfig([

 {path: '/LogIn', name: 'LogIn', component: Component, useAsDefault: true},

])
export class AppComponent {
 title = 'Ebay clone';
}

LogInPage.component.ts 的代码

import {Component} from 'angular2/core';
import {Router} from 'angular2/router';
@Component({
 selector: 'LogInPageSelector',
 templateUrl: 'app/loginpage.component.html',
 styleUrls: ['app/loginpage.component.css']
})
export class LogInComponent {
 constructor(private LogInService: LogInComponent, private _router: Router) { }
}

loginpage.component.html 代码:

<html>
 <h1>Hello</h1>
</html>

【问题讨论】:

    标签: javascript html angular


    【解决方案1】:

    我认为您忘记在主 HTML 文件中包含“router.dev.js”文件:

    <script src="node_modules/angular2/bundles/router.dev.js"></script>
    

    【讨论】:

      猜你喜欢
      • 2015-06-29
      • 1970-01-01
      • 2017-07-31
      • 2020-04-30
      • 1970-01-01
      • 2016-05-17
      • 1970-01-01
      • 1970-01-01
      • 2016-09-04
      相关资源
      最近更新 更多