2016-07-27 32 views
0

我正在處理用戶輸入電子郵件地址的電子郵件輸入表單。我需要確保電子郵件地址是小寫字母。我正在努力的是,我能夠採取一個數組或字符串,並將其轉換爲小寫或大寫。但是,因爲這是要求用戶輸入一些我一直在使用這些相同的技術遇到麻煩。angular.js輸入設置爲小寫

%zip-input-md{ type: "email", "ng-model" => "vm.form.email", required: true, 'ng-maxlength' => 50, 'ng-disabled' => 'vm.form.validated_email' } 
    Email address 

我最初認爲的解決方案是{{ lowercase_expression | lowercase}}但只有很適合現有的字符串。

在控制器的後端,vm.form.email在submitForm方法中定義。

vm.submitForm = (isValid) -> 
    success = -> 
     TokenService.post vm.form.email, vm.form.password 
     .then tokenServiceSuccess, tokenServiceError 
     .then tokenServiceFinally 
     return 

如果有人有任何好的想法,我真的很感激它。

回答

1

注入在控制器的服務$filter然後:

vm.submitForm = (isValid) -> 
    success = -> 
     TokenService.post $filter('lowercase')(vm.form.email), vm.form.password 
     .then tokenServiceSuccess, tokenServiceError 
     .then tokenServiceFinally 
     return