我有列表组件<div class="parent-1">
<div class="child-1">
<div class="child-1-1">C1</div>
<div class="child-1-2">Some text</div>
</div>
<div class="child-2">
<div class="child-2-1">Another text</div>
</div>
</div>
和详细信息组件OrganizationsComponent
(模式对话框),使用OrganizationDetailComponent
进行导航。
当导航从列表发生到详细信息 [ OrganizationsComponent(list)&gt;&gt;&gt; OrganizationDetailComponent(detail)],再次调用 list 中的route
(来自onActivate
接口的方法)。
我希望只会在详细信息上调用OnActivate
,例如,而不是列表(调用者)
如果这是正常行为,是否有办法停止调用此方法onActivate
的原点,在这种情况下,在列表中?
环境:
遵循代码:
列出代码(部分):
-HTML
onActivate
-DART
<div class="container-list">
<material-fab raised (trigger)="goToDetail(null)">
<material-icon icon="add"></material-icon>
</material-fab>
<br/>
<material-list class="shadow-box-material-list" elevation="2">
<div *ngFor="let o of organizations">
<material-list-item>
<div>
<h4 class="material-list-item-content"><strong>{{o.name}}</strong></h4>
<p class="material-list-item-content">{{o.code}}</p>
</div>
<span class="row-spacer"></span>
<div class="material-list-item-secondary">
<div>
<material-menu [menu]="menuModel" (click)="selectOrganization(o)">
</material-menu>
</div>
</div>
</material-list-item>
<hr>
</div>
</material-list>
</div>
<router-outlet [routes]="rotas"></router-outlet>
详情(部分):
-HTML
class OrganizationsComponent implements OnActivate, OnDestroy {
final List<RouteDefinition> rotas = [
new RouteDefinition(
routePath: AppRotas.appLayoutHomeRoute,
component: app_layout_home.AppLayoutHomeComponentNgFactory,
useAsDefault: true
),
new RouteDefinition(
routePath: AppRotas.organizationDetailRoute,
component: organization_detail.OrganizationDetailComponentNgFactory,
),
new RouteDefinition(
routePath: AppRotas.organizationDetailAddRoute,
component: organization_detail.OrganizationDetailComponentNgFactory,
),
];
final Router _router;
List<Organization> _organizations;
OrganizationsComponent(this._router);
// ** HERE IS CALLED AGAIN WHEN NAVEGATES TO DETAIL (calling goToDetail() method) **
@override
onActivate(routeStatePrevious, routeStateCurrent) async {
_organizations = await _organizationService.getOrganizations();
}
@override
ngOnDestroy() async {
_appLayoutService.searchEnabled = false;
}
void goToDetail(Organization organization) {
if (organization == null) {
_router.navigate(AppRotas.organizationDetailAddRoute.toUrl());
} else {
_router.navigate(AppRotas.organizationDetailRoute.toUrl(parameters: {
AppRotas.organizationUuidParameter: organization != null ? organization.id : null
}));
}
}
List<Organization> get organizations {
return _organizations;
}
// ...
}
-DART
<modal [visible]="true">
<material-dialog headered class="headered-dialog">
<div header>
<h3>{{labelOrganization}}</h3>
</div>
<material-content>
<material-input class="width-300" [(ngModel)]="organization.name" floatingLabel [label]="labelName" required [requiredErrorMsg]="msgValorRequerido"></material-input>
<material-input [(ngModel)]="organization.code" floatingLabel [label]="labelCode"></material-input>
</material-content>
<div footer>
<material-button (trigger)="saveOrganization()">{{buttonLabelSave}}
<material-icon icon="save"></material-icon>
</material-button>
<material-button autoFocus (trigger)="goBack()">{{buttonLabelBack}}
<material-icon icon="arrow_back"></material-icon>
</material-button>
</div>
</material-dialog>
</modal>