В дополнение к ответу cgTag:
Я бы рекомендовал установить значение по умолчанию также в ngOnChanges
ловушке жизненного цикла.
export class MyComponent implements OnInit, AfterViewInit {
// moved default value to static property, to prevent duplication
private static defaultImgName: string = "img_one";
@Input() public imgName: string = MyComponent.defaultImgName;
constructor() {
// after compiling typescript to javascript,
// imgName property will actually be populated here
}
ngOnChanges(values: SimpleChanges) {
// please note, that ngOnChanges is not executed,
// if component is initialized w/o any bindings
// this will be executed on every change of imgName,
// so if you need it to be checked only once - you can do that
// with the method values.imgName.isFirstChange()
if (values.imgName && values.imgName.currentValue === undefined) {
this.imgName = MyComponent.defaultImgName;
}
}
ngOnInit() {
console.log("Inside ng on init");
}
ngAfterViewInit() {
console.log("imgName value is: ${this.imgName}")
}
}
Используйте продвижение /
/file.x
, Который будет только соответствовать верхнему уровню file.x, но не каждый опускается, в "want/file.x", говорит.