Как получить пулю в items.component.ts Адрес такой как http://domain.com/slug Так что если я нажму на элемент nav, я хочу передать слизню в другой компонент.Угловой 2 проход var в компоненте A к компоненту B
navbar.component.html:
<ul class="nav navbar-nav">
<li *ngFor="let item of items"><a (click)="changeParam(item.slug)" [routerLink]="[item.slug]" [routerLinkActive]="['is-active']">{{item.name}}</a></li>
</ul>
navbar.component.ts:
import { Component, OnInit} from '@angular/core';
import {ActivatedRoute} from "@angular/router";
@Component({
selector: 'app-navbar',
templateUrl: './navbar.component.html',
styleUrls: ['./navbar.component.css']
})
export class NavbarComponent implements OnInit {
changeParam($slug) {
this.sluggie = $slug;
}
constructor() { }
ngOnInit() {
}
}
items.component.ts:
import { Component, OnInit , Output } from '@angular/core';
import {ItemService} from "./item.service";
import { Router, ActivatedRoute, Params } from '@angular/router';
@Component({
selector: 'app-items',
templateUrl: './items.component.html',
styleUrls: ['./items.component.css'],
providers: [ItemService]
})
export class ItemsComponent implements OnInit {
id: string;
private sub: any;
constructor(private route: ActivatedRoute) {
}
ngOnInit() {
this.sub = this.route.params.subscribe(params => {
this.id = params['slug'];
});
}
}
app- component.html:
<div class="container">
<app-navbar></app-navbar>
<h1>
{{title}}
</h1>
<router-outlet></router-outlet>
<app-items></app-items>
</div>
Как навигация и навигация связаны. Не могли бы вы добавить еще код. Какие селекторы имеют компоненты. См. Также https://angular.io/docs/ts/latest/cookbook/component-communication.html –
Не зная селекторов рассматриваемых компонентов, я не знаю, где они применяются. –
@Bas: Вы вызываете компонент элементов внутри компонента navbar? –