如何根据其他表单字段值禁用离子表单字段?

时间:2018-03-13 13:16:31

标签: angular ionic-framework

有一个离子选择

package main

import (
    "fmt"
    "regexp"
)

var (
    virtualHost string
    domainRegex *regexp.Regexp
)

func extractSubdomain(host string) string {
    matches := domainRegex.FindStringSubmatch(host)
    if matches != nil && len(matches) > 1 {
        return matches[1]
    }
    return ""
}

func init() {
    // virtualHost = os.GetEnv("VIRTUAL_HOST")
    virtualHost = "login.localhost:3000"

    domainRegex = regexp.MustCompile(`^(?:https?://)?([-a-z0-9]+)(?:\.` + virtualHost + `)*$`)
}

func main() {
    // host := req.host
    host := "http://acme.login.localhost:3000"

    if result := extractSubdomain(host); result != "" {
        fmt.Printf("Subdomain detected: %s\n", result)
        return
    }

    fmt.Println("No subdomain detected")
}

如果离子选项值为“否”,我想禁用离子输入

 <ion-select interface="popover" formControlName="window_exists"  (ionChange)="openWindow()" type="text">
          <ion-option value="Y">Yes</ion-option>
          <ion-option value="N">No</ion-option>
        </ion-select>

请指导

1 个答案:

答案 0 :(得分:1)

您需要将$ event作为参数传递,

<ion-select interface="popover" formControlName="window_exists"  (ionChange)="openWindow($event)" type="text">
  <ion-option value="Y">Yes</ion-option>
  <ion-option value="N">No</ion-option>
</ion-select>

并添加这样的禁用属性,

<ion-input disabled="{{isDisabled}}" type="number" min="0" formControlName="ml_window_no" required clearInput></ion-input>

现在,您必须在.ts文件中添加此代码,

isDisabled:boolean = false;

openWindow(event){
     console.log('event',event);
     if (event == 'N') {
       console.log('no');
       this.isDisabled = true;
     }else{
       console.log('yes');
       this.isDisabled = false;
     }
}

感谢。