1

I'd like to add lang='fa' attribute to all input:text in my form with angular .

with a little condition : if body has class fa all input:text not email type get lang="fa" attribute .

i know how to do it with jquery but i don't know how to do it in angular way .
here is my fiddle with Jquery : Demo
Jquery :

$(document).ready(function(){
        if($("body").hasClass('fa')){
            if('input:text'){
                $('input:text').attr('lang','fa');
            }
        }
    });
5
  • you have to write your own directive Commented Jan 23, 2015 at 12:29
  • ok,but where should i add the custom directive ? in body ? Commented Jan 23, 2015 at 12:32
  • Or you can still use jQuery because jQuery works well with AngularJS. AngularJS is a framework and jQuery is a liblary, if you can do something easier in jQuery than in Angular just do it :) Commented Jan 23, 2015 at 12:33
  • have a look here: stackoverflow.com/questions/15696416/… Commented Jan 23, 2015 at 12:34
  • thank you guys, i get the answer . @szapio that's not the best way to use jquery in angular Commented Jan 23, 2015 at 12:38

1 Answer 1

2

You can add functionality to the input directive (or any directive). This is simply done by declaring it once again. The following will do what you want:

// we assume that the var isFa is already set, e.g as:
var isFa = angular.element(document.body).hasClass('fa');

app.directive('input', function() {
    return {
        restrict: 'E',
        link: function(scope, elem) {
            if( isFa && elem.attr('type') === 'text' ) {
                elem.attr('lang','fa');
            }
        }
    };
});

No need for jQuery. See fiddle: http://jsfiddle.net/b37wdm07/

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.