0

My directive looks as follows:

directive('setAttribute', function () {
        return {
            restrict: 'A',
            require: 'ngModel',
            link: function ($scope, element, attrs, ctrl) {
                var prop = $scope.$eval(attrs.setAttribute);

                prop.validationRulesToApply.forEach(function (rule) {
                    attrs.$set(rule.name, rule.val);

                });
            }
        }
    });

As you can this one is for setting attributes dynamically. In spite of attributes are set properly(i can see them in final HTML) no validation is triggered. When i output $error object with curly braces - it is empty! Do i miss something important when setting attributes?

Aleksei Yerokhin
  • 869
  • 4
  • 9
  • 22

1 Answers1

0

Are these validation rules you are trying to add in setAttribute directive?

If it so, you are doing in wrong way. When you use $set, it just adds attribute to HTMl, but doesnot compile them. Hence, you won't get results as you are seeking.

You need to add it to pre compile I think this solution may help you.

Add directives from directive in AngularJS

Community
  • 1
  • 1
Raj
  • 103
  • 5