Angular 2版本:2.0.0-alpha.44
我一直在尝试在Angular 2中进行路由.虽然我能够完成正常的路由,但是当我介绍子路由时,我遇到了一些问题.以下是plnkr上的示例(http://plnkr.co/edit/Y5doqU1WcEe4Ldr7KfPJ)
以下是快速参考的代码.我正在努力实现以下路由
App
/\
/ \
HomeCmp HelloCmp
\
\
ChildCmp
Run Code Online (Sandbox Code Playgroud)
下面是我如何配置我的路径
import {bootstrap, bind, Component, View} from 'angular2/angular2'
import {RouteConfig, RouteParams, ROUTER_DIRECTIVES, APP_BASE_HREF, ROUTER_BINDINGS} from 'angular2/router'
@Component({
selector: 'child-cmp'
})
@View({
template: `
<div>
<h3>Whats up</h3>
</div>
`
})
class ChildCmp { }
// ************************ Hello Component ***********************************
@Component({
selector: 'hello-cmp'
})
@View({
template: `
<div>
<h2>Hello there !</h2>
<router-outlet></router-outlet>
</div>
`,
directives: ROUTER_DIRECTIVES
})
@RouteConfig([
{path: '/', component: ChildCmp, as: 'ChildCmp'}
])
class …Run Code Online (Sandbox Code Playgroud) 使用Angular 2版本:2.0.0-alpha.44
我试图从组件发出输出信号.我在这里关注了Angular文档 .Below是我的组件的代码
@Component({
selector: 'summary'
})
@View({
directives: [NgFor, NgIf, ROUTER_DIRECTIVES, LogoutComponent, BarChartDirective, SunburstChartDirective],
templateUrl: 'view/summary-component.html'
})
export class SummaryComponent {
@Output() loadSummary: EventEmitter = new EventEmitter();
project: Project;
data: any;
constructor(public http: Http,
public router: Router,
public xxxGlobalService: XXXGlobalService) {
console.log("SummaryComponent: Created");
this.getSummary()
}
getSummary() {
this.project = this.xxxGlobalService.getOpenedProject();
var url = "/project_summary?username="+ this.xxxGlobalService.getUser().name + "&project_id=" + this.project.id;
this.http.get(url)
.map(res => res.json())
.subscribe(
data => this.extractData(data),
err => this.logError(err),
() => console.log('SummaryComponent: Successfully got the …Run Code Online (Sandbox Code Playgroud)