0
這裏的問題是,單擊查看作業後,頁面成功轉到主細節,然後快速轉到路徑:'',組件:JobsComponent。 向下跌破這就是我執行查看作業按鈕,主從Angular2路徑解析爲路徑:''在主細節
具有指向詳細const appRouts: Routes = [
{
path: '',
component: JobsComponent
},
{
path: 'learner',
component: LeanershipsComponent
} {
path: 'cvTips',
component: CvTipsComponent
},
{
path: 'detail/:id',
component: JobDetailComponent
}
]
<table *ngFor="let l of getKeys()" class="table">
<tr class="odd hide-jobs">
<td class="tbl-logo"><img src="assets/img/job-logo5.png" alt=""></td>
<td class="tbl-title">
<h4> {{jobs[l].title}}<br><span class="job-type">full time</span></h4>
</td>
<td>
<p>{{jobs[l].company}} </p>
</td>
<td>
<p><i class="icon-location"></i>{{jobs[l].location}}</p>
</td>
<td>
<p>{{jobs[l].salary}}</p>
</td>
<td routerLink="./detail/{{l}}" class="tbl-apply"><a href="">View Job</a></td>
<td class="tbl-apply"><a href="">Apply now</a></td>
</tr>
</table>
此代碼成功獲取主詳細路徑
路由文件來自firebase的id然後將它們傳遞給循環*ngFor
import {
Component,
OnInit
} from '@angular/core';
import {
Service
} from '../../service/service'
@Component({
selector: 'app-jobs',
templateUrl: './jobs.component.html',
styleUrls: ['./jobs.component.css'],
providers: [Service]
})
export class JobsComponent {
jobs
key = []
constructor(private todoService: Service) {
let promise = todoService.getJobs();
promise.then(snapshot => {
this.jobs = snapshot.val();
var listJobs = snapshot.val();
// console.log(listJobs);
})
this.getKeys();
}
ngAfterViewInit() {
this.getKeys();
}
getKeys() {
try {
this.key = Object.keys(this.jobs);
//console.log(this.key);
} catch (e) {
// console.log(e);
}
return this.key;
}
}
謝謝你。粗心的錯誤 –