Javascript 动态更改占位符文本
我对离子输入的占位符有问题。我想在选中复选框时更改占位符,在未选中任何内容时再次显示该占位符。我的一些代码:Javascript 动态更改占位符文本,javascript,angular,ionic-framework,logic,placeholder,Javascript,Angular,Ionic Framework,Logic,Placeholder,我对离子输入的占位符有问题。我想在选中复选框时更改占位符,在未选中任何内容时再次显示该占位符。我的一些代码: placeholderText = "Write something"; <ion-input name="search" type="search" ngModel [placeholder]="placeholderText&q
placeholderText = "Write something";
<ion-input
name="search"
type="search"
ngModel
[placeholder]="placeholderText"
#searchCtrl="ngModel"
></ion-input>
dummyArray: { name: string; x: string; checked: boolean }[] = [
{
name: "a",
x: "grg",
checked: false,
},
{
name: "b",
phone: "ggg",
checked: false,
},
]. This is a dummy date array of objects.
<ion-list *ngFor="let dummy of dummyArray">
<ion-label> {{dummy.name}}</ion-label>
<ion-checkbox></ion-checkbox>
</ion-list>
placeholder text=“写点什么”;
dummyArray:{name:string;x:string;checked:boolean}[]=[
{
名称:“a”,
x:“grg”,
勾选:假,
},
{
名称:“b”,
电话:“ggg”,
勾选:假,
},
]。这是对象的虚拟日期数组。
{{dummy.name}
我需要的是更改占位符文本,如果有人从复选框中被选中为具有空字符串占位符,并且如果没有人被选中以显示文本
我怎样才能做到这一点,请帮助
Thank当选中的属性发生更改时,Ionic CheckBox会发出一个事件。每当复选框更改时,我们需要检查并更新占位符值 创建占位符作为变量,并在复选框更改时更新它
# Component HTML File
<ion-checkbox slot="end" [(ngModel)]="checkBoxValue"
(ionChange)="checkBoxChangeHandle($event)"></ion-checkbox>
<ion-input [placeholder]="dynamicPlaceholder"></ion-input>
# Component.ts
export class AppComponent implements OnInit {
dynamicPlaceholder: string = "write Something"
checkBoxValue:boolean = false
constructor(){}
ngOnInit(){}
checkBoxChangeHandle(checkValue) {
this.dynamicPlaceholder = checkValue ? "": "Write Something";
}
}
#组件HTML文件
#组件技术
导出类AppComponent实现OnInit{
dynamicPlaceholder:string=“写点什么”
checkBoxValue:boolean=false
构造函数(){}
ngOnInit(){}
checkBoxChangeHandle(checkValue){
this.dynamicPlaceholder=checkValue?”:“写点什么”;
}
}
希望这能起作用。我不熟悉ion inpt,但是如果你想在js/html中使用它,这个提琴可以帮助你:嗨,谢谢你的回复。我试过这个代码,但不起作用。我不知道为什么,但我认为它的事件功能并不完全好。它没有正确更改占位符..只需检查发出的事件的值。日志(checkValue)。如果它返回你所做的。那么这是唯一的办法。ty@Mohammed IsmailHappy;)