我一直在关注这个Angular 中的路由教程,但它不起作用。当我使用“comp”选择器放置它的 HTML 代码时,它可以工作,但是当我尝试使用 router-outlet 路由它时,它只显示来自index.html
.
我有以下内容:
main.ts:
import * as ng from 'angular2/angular2';
import {Comp} from './comp';
@ng.Component({
selector: 'my-app'
})
@ng.View({
directives: [ng.formDirectives, ng.RouterOutlet],
template: `
<nav>
<ul>
<li>Start</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
<main>
<router-outlet></router-outlet>
</main>
`
})
@ng.RouteConfig([{ path: '/', component: Comp }])
class AppComponent {
}
ng.bootstrap(AppComponent, [ng.routerInjectables]);
比较:
import * as ng2 from 'angular2/angular2';
@ng2.Component({
selector: 'comp'
})
@ng2.View({
template: `
<h1>hi<h1>
`
})
export class Comp {
constructor() {
}
}
索引.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Test3</title>
<script src="lib/traceur/traceur.js"></script>
<script src="lib/system.js/dist/system.js"></script>
<script src="lib/angular2-build/angular2.js"></script>
<script src="lib/angular2-build/router.dev.js"></script>
<script>
System.config({
packages: {
'js': {
defaultExtension: 'js'
}
}
});
System.import('/js/main');
</script>
</head>
<body>
<h1>Hello There</h1>
<my-app></my-app>
</body>
</html>