How to set validity in directive (angularjs)

前端 未结 2 842
抹茶落季
抹茶落季 2020-12-17 07:03

Is there a way to set an input validity inside a directive? The input present in the directive\'s template.

Lets say I have template:



        
2条回答
  •  旧时难觅i
    2020-12-17 07:16

    You don't need to use elem in order to get the controller, just add it as a param to the link function, and set require to ['ngModel'] in order to get the model ctrl.

     require: ['ngModel'],
     link: function (scope, elem, attrs, ctrl) {
    
          someObj = {val: '123'};
    
          scope.check = function () {
            var result = false;
            ctrl.$setValidity(result);
          };
    
        }
    

提交回复
热议问题