2017年9月13日 星期三

透過 $http.post 傳遞參數到 server 出現訊息 : JSON 要求太長,無法還原序列化

通常是因為傳遞陣列時,陣列元素總數超過預設上限300,可透過以下方式加大上限
於 web.config 中加入
<add key="aspnet:MaxJsonDeserializerMembers" value="30000" />

2017年9月12日 星期二

自訂錯誤驗證

整體判斷 : if (!$scope.form1.$valid)
單獨判斷 : if (!$scope.form1.$error.requirepaycode)
強制判斷 : $scope.form1.報件單號.$validate(); (考慮有些情況不會自動觸發函數)

.directive("requirepaycode", function () {
            return {
                restrict: 'A',
                require: "ngModel",
                link: function (scope, element, attributes, ngModel) {
                    ngModel.$validators.requirepaycode = function (modelValue, viewValue) {
                        return !scope.selectingPayCode() || (modelValue != null && modelValue != "");
                    }                    
                }
            };
        })

<input requirepaycode name="報件單號" entertab ui-mask="X999999999999" model-view-value="true" class='form-control' ng-focus="focusPayCode()" ng-disabled="!newmode && !editmode" ng-model='selectData["報件單號"]'><span style='color:red' ng-show="form1['報件單號'].$error.requirepaycode">*</span>

2017年9月8日 星期五

ng-if 使用注意事項

如果同時使用 ng-model,因為 ng-if是自己的 scope,所以需要用物件綁定才能正常運作,否則切換 ng-if 的值會重新產生scope,ng-model value 會回到預設值
ng-model="word.value" ng-if="show"

或者可以直接綁定parent 避免此問題
ng-model="$parent.wordvalue" ng-if="show"

ui-mask 使用方式

讓提示字元變成 ng-model 的一部分
ui-mask="X999999999999" model-view-value="true"

若輸入不完整也允許接受
ui-options="{clearOnBlur:false,allowInvalidValue:true }"

改變提示字元
ui-mask-placeholder-char="space"

自訂遮罩字元(以卡號為例)
.config(['uiMask.ConfigProvider', function (uiMaskConfigProvider) {
    uiMaskConfigProvider.maskDefinitions({ 'C': /[a-zA-Z0-9*]/ });
}])
 <input entertab ui-mask="CCCC CCCC CCCC CCCC CCCC" ui-mask-placeholder-char="space" ui-options="{clearOnBlur:false,allowInvalidValue:true }" model-view-value="false" type='text' class='form-control' ng-model='selectData["卡號"]'>

Entity Framework 建立新物件並儲存後馬上取得關聯資料

使用 CreateProxy 建立物件,不要直接 new var newmodel = _contextXXX.CreateProxy<yyy>(); ... _contextXXX.yyy.Add(newmodel); await _contextXXX.SaveC...