angularjs - Passing value to directive in directive ng-show -



angularjs - Passing value to directive in directive ng-show -

im trying extend angular input directive error box appended after automatically shown when input has errors.

<form name="form"> <input with-error show-error-if="form.input.$error.required" name="input" required/> <!-- error directive should appended here , shown when errors --> </form> <!-- working directive --> <error field-name="input" show-if="form.input.$error.required"></error>

so directive specified follows:

app.directive("witherror", [ '$compile', function($compile) { homecoming { restrict: "a", replace: true, scope: { showerrorif: "@" }, link: function(scope, element, attrs) { if (element.next().length) { element.next().insertbefore(element); } var newelhtml = '<error field-name="' + attrs.name + '" show-if="{{ showerrorif }}"></error>'; var newel = angular.element(newelhtml); newel.insertafter(element); $compile(newel)(scope); } } } ]);

and error directive specified:

app.directive("error", [ function() { var errortemplate; errortemplate = '<div class="error" ng-show="$parent.{{ showif }}">{{ errors[fieldname] }}</div>'; homecoming { restrict: "e", replace: true, scope: { fieldname: "@", showif: "@" }, template: errortemplate, controller: function($scope, errortexts) { $scope.errors = errortexts; } } } ]);

the problem appended directive not hide or show depending on if there errors while manually added 1 does?

fiddle

angularjs angularjs-directive ng-show

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -