在角度重定向到另一个页面它被使用
<a [routerLink]="['/editar-producto',producto.id]" class="btn btn-warning">Editar</a>
但是在离子中是什么方法?应该怎么放在app.component.ts中来接收这些参数呢?
this.pages = [
{ title: 'Home', component: HomePage },
{ title: 'List', component: ListPage },
{ title: 'Productos', component: ProductsPage },
{ title: 'Agregar producto', component: CreateProductPage }
];
但要接收参数?
在 angular4 中,配置是
import { ModuleWithProviders } from '@angular/core';
import {Routes, RouterModule} from '@angular/router';
//Componentes
import {HomeComponent} from './components/home.component';
import {ErrorComponent} from './components/error.component';
import {ProductosComponent} from './components/productos.component';
import { ProductoAddComponent } from './components/producto-add.component'
import {ProductoDetailComponent} from './components/producto-detalle.component';
import {ProductoEditComponent} from './components/producto-edit.component';
const appRoutes: Routes = [
{path: '', component: HomeComponent},
{path: 'home', component: HomeComponent},
{path: 'productos', component: ProductosComponent},
{path: 'crear-producto', component: ProductoAddComponent},
{path: 'producto/:id', component: ProductoDetailComponent},
{path: 'editar-producto/:id', component: ProductoEditComponent},
{path: '**', component: ErrorComponent}
];
export const appRoutingProviders: any[] = [];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
但是在离子中我没有这些
{path: 'editar-producto/:id', component: ProductoEditComponent},
您已经发现必须如何在 products 组件中放置一个名为
那么这意味着 ProductEditPage 将收到一个名为 idProduct 的 get 参数。
在产品编辑后完成
public idProduct;
声明属性然后在构造函数中
这样我就有了href的id。在产品视图中添加
由于 get url 没有在 ionic 中使用,因为它是面向移动设备的。