私はアングラ2で新しいです、そして、私はニュースのウェブサイトを作成しようとしています。例えば、ホームページには異なるカテゴリの異なる記事が含まれています。 「/スライダー/ 1条」、「/スポーツ/ article3」など。角度2でダイナミックルータリンクを作成する方法は?
私はループにしてみてください。
は、だから私は、JSONの結果は、リンク元が含まれているAPIからのスライダ部で例えば記事を取得しますhtmlの結果はルータリンクが機能しません!ここで
は、サンプルコード
Home.component.html // **そのリンクが '/スポーツ'
<a [routerLink]="[item.link]">{{item.title}}</a>
Route.config.ts
export const rootRouterConfig: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'sport', component: SportComponent }
];
が含まれていると言うことができますです私はエラーを言及することを忘れないでください
私はUncaught (in promise): TypeError: Cannot read property 'outlets' of null
*ngIf="mainNewsItem?.length > 0"
ngif *を使用
import { Component, OnInit } from '@angular/core';
import { HomeService } from '../../_services/home.service';
import { ContentInfo } from '../../_models/content';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css'],
providers: [HomeService]
})
export class HomeComponent implements OnInit {
mainNewsItem: ContentInfo[];
constructor(private _homeService: HomeService) {
this.mainNewsItem = [];
}
ngOnInit() {
// Get Main News Item
this._homeService.getMainNewsItem()
.subscribe(content => this.mainNewsItem = content,
error => this._homeService = <any>error)
;
}
}
Home.component.ts divがなくなったが、なぜか? mainNewsItemにデータが含まれていることを意味します。
感謝:)
することができます:あなたの
SportComponent
あなたはパラメータを受け取るためにあなたのコンストラクタでActivatedRouteを注入することができるで{ path: 'sport/:articleTitle', component: SportComponent },
をあなたはプランナーにあなたの問題を再現しますか?コンソールのエラーは何ですか –
[ドキュメントに従って](https://angular.io/docs/ts/latest/guide/router.html#!#route-def-with-parameter)経路パラメータ。理解できない場合は、お気軽にお問い合わせください! – trichetriche
エラー - 未知(約束):TypeError:ヌルのプロパティ 'アウトレット'を読み取れません。 –