【发布时间】:2017-03-09 04:54:31
【问题描述】:
所以我尝试了我在网上找到的所有东西,但没有任何效果。
所以我关注了关于路由的角度文档:https://angular.io/docs/ts/latest/guide/router.html
这是我的 login.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-login',
template: './login.component.html',
styleUrls: ['./login.component.css'],
})
export class LoginComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
还有我的 login.component.html
<p>Test login</p>
<router-outlet></router-outlet>
错误:错误:找不到加载“LoginComponent”的主要出口 在getOutlet
所以我有点迷路了。我尝试使用:“模板:(HTML HERE)”而不是templateUrl,同样的事情......
谢谢!
顺便说一句,它不是重复的,因为 ROUTER_DIRECTIVES 已被弃用。
【问题讨论】:
-
发布你的app.module.ts,路由器模块/文件,如果可能的话,创建工作plunkr。可能加载的根组件不包含路由器出口。
-
另外,如果你为模板使用 html 文件,组件装饰器应该使用
templateUrl而不是template -
@ParthGhiya 我回家后会发布。
-
@garth74 我尝试了两种方式。带有模板 url 和一个单独的文件以及带有 HTML 的模板。
标签: angular