【发布时间】:2018-12-16 18:54:43
【问题描述】:
我需要向现有组件添加一个名为“dataTestValue”的新属性。这是一个类似于选项卡的简单组件:
export class TabComponent implements OnInit {
@Input('active') active = false;
@Input('title') title: string;
dataTestValue: string;
constructor() { }
ngOnInit() {
this.dataTestValue = this.title.replace('/ /g', '_');
console.log(this.dataTestValue);
}
}
因为“title”属性可以包含空格,我需要替换并将其转换为小写。
我设法只用这个替换了第一个空白:
this.dataTestValue = this.title.replace(' ', '_');
由于某种原因,全局方法不起作用,它只是打印原始值。有什么想法吗?
P.S:如果我使用“ngOnInit”生命周期挂钩,请通知我。
【问题讨论】:
标签: javascript angular typescript