我已经成功地在Angular JS中为我的其他组件在同一个项目和新组件中实现了路由参数,但它不起作用,我无法理解代码中的问题。无法读取Angular 2中的路由参数
下面是我的路线的代码文件
import { Routes, RouterModule } from '@angular/router';
import { CustomerBillComponent } from '../components/customer_bill.component';
const routes: Routes = [
{ path: 'add-bill', component: CustomerBillComponent },
{ path: 'add-bill/:customer_reference', component: CustomerBillComponent },
];
export const routing = RouterModule.forRoot(routes);
(我尝试使用不同的路线还可以,但没有奏效)
下面是我的CustomerBillComponent.ts文件中的代码
ngOnInit() {
//When I visit /#/add-bill/CR452152
let route_location = location['hash'].split('/')[1].toLowerCase();
console.log(route_location); //prints add-bill in Console
var customer_reference = this.route.snapshot.params['customer_reference'];
console.log(customer_reference); //prints undefined
}
我错过了什么
在此先感谢!
同样的问题,相同的结果 – Sajad
您是否找到任何解决方案? – Sajad