小编And*_*riy的帖子

Angular 4反应形式-显示值

我正在使用反应形式方法。我有一个具有对应的formControl对象的输入字段,并且在键入时我正在对值进行格式化-使所有输入大写。

那当然工作得很好-在视图和formControl中也会更新该值。

The issue is That I would like to send to server the original value and not the formmated value (uppercase)

So I need something like value, and value for display in the formControl object.

See plunker - formatting value formControl

template:

  <input type="text" 
         class="form-control" 
         (blur)="handleOnBlur($event)"
         (input)="onChange($event)"
         formControlName="name">
Run Code Online (Sandbox Code Playgroud)

model:

    valueForModel: string; 
    valueForDisplay: string;
    public myForm: FormGroup;        

 onChange(event) {
    const value = event.target.value;
    this.valueForModel = value;
    this.valueForDisplay = value.toUpperCase();

    event.target.value = this.valueForDisplay;
 }

 handleOnBlur(event) {

   consol.log(this.valueForModel);
    // Herer I'm calling …
Run Code Online (Sandbox Code Playgroud)

model-view-controller model reactive-programming form-control angular

5
推荐指数
1
解决办法
4814
查看次数

Angular 5 - 如何在DatePipe中使句点字段类型为小写

在Angular 5.1中使用DatePipe,我需要以小写形式格式化句点字段类型(AM/PM).根据文件,

Tuesday, December 19, 7:00 am 
Run Code Online (Sandbox Code Playgroud)

应该

date:'EEEE, MMMM d, h:mm a'
Run Code Online (Sandbox Code Playgroud)

但是,句点字段类型始终以大写形式显示,所以我看到:

Tuesday, December 19, 7:00 AM
Run Code Online (Sandbox Code Playgroud)

我做错了什么,或者这是Angular日期格式化的已知缺陷?

angular-pipe angular-date-format angular angular5

3
推荐指数
1
解决办法
2286
查看次数

无法选择反应形式角度的多个值

我在我的应用程序中使用 Angular 反应形式。我想为多选表单控件设置多个值。

mycomponent.html

<select id="placeType" 
        class="form-control" 
        [multiple]="true" 
        style="height:200px" 
        formControlName="kalase">
  <option value="" selected="selected" disabled>Select Place Type</option>
  <option *ngFor="let kalase of types" [value]="kalase" [innerHtml]="kalase"></option>      
</select>
Run Code Online (Sandbox Code Playgroud)

mycomponent.ts

types: string[] = ["BAR", "CAFE", "RESTAU", "hotels", "club"];

this.placeForm = this.formBuilder.group({
  kalase: [[this.types[1], this.types[3]]]
});
Run Code Online (Sandbox Code Playgroud)

问题是选择控件中唯一选定的值是类型数组的第四项(“hotels”)。谁能告诉我我做错了什么?

angular

1
推荐指数
1
解决办法
3914
查看次数