为什么以下警卫没有id
可用?
@Injectable()
export class ProjectDetailsGuard implements CanActivate {
constructor(private activatedRoute: ActivatedRoute) { }
canActivate() {
const id = this.activatedRoute.snapshot.params['id'];
console.log(id); // <-- undefined
}
}
在组件内部实现时,相同的代码可以正常工作。
答案 0 :(得分:4)
ActivatedRoute
只有在激活路线后才能提供参数。如果需要在params
被激活之前获得canActivate
,请ActivatedRouteSnapshot
方法尝试使用canActivate(activatedRoute: ActivatedRouteSnapshot) {
const id = activatedRoute.params['id'];
console.log(id);
}
MyDataset <- RxXdfData("./path/dataset.xdf") #the dataset you are using
# replace transFormedCol with the name of the col you want to use
rxDataStep(inData = MyDataset,
outFile = MyDataset,
transforms = list(
transFormedCol = ifelse(col1 == '1',col2*0.5,
ifelse(col2 == '2', col2*0.8))), #etc...
overwrite = TRUE
)