mdl-textfield not taking ngModel changes into account

前端 未结 3 1216
礼貌的吻别
礼貌的吻别 2021-01-06 14:34

I am facing an issue regarding the mdl-textfield\'s behavior

On the below plnkr, follow the steps:

  1. click on \"groups working\"
  2. cl
3条回答
  •  天涯浪人
    2021-01-06 15:26

    When you an mdl-textfield__input's ng-modelvalue is set after the mdl component is registered, the mdl-textfield does not get the is-dirty class, thus does not behave the way it should.

    You can use this directive on your `mdl-textfield__input field :

    "use strict";
    (function(){
      let mdlTfFix = () => {
        return {
          restrict: "C",
          require: "ngModel",
          link: ($scope, $element, $attrs, ngModelCtrl) => {
            $scope.$watch(() => {
              return ngModelCtrl.$modelValue;
            }, (newVal, oldVal) =>{
    
              if(typeof newVal !== "undefined" && newVal !== "" && newVal !== oldVal){
                $element.parent().addClass("is-dirty");
              }
              else{
                $element.parent().removeClass("is-dirty");
              }
            });
          }
        };
      };
    
      mdlTfFix.$inject = [];
      app.directive("mdlTextfieldInput", mdlTfFix);
    
    })();
    

提交回复
热议问题