angularjs - Unable to get the resolved attributes within custom directive -


i have been trying write custom directive input field dynamic id, in directive unable correct id.

<input id="myinput{{$index}}" my-dir="fn()"/>  myapp.directive('mydir', function ($parse) {     var obj = {         require: "ngmodel",         link: {             post: function (scope, element, attrs) {                 var fn = $parse(attrs.mydir);                 var elementid = element.attr('id');                 console.log(elementid); // here see myinput{{$index}} instead of myinput0, time angular not resolving value                      }         }     };     return obj; }); 

my question be, how can resolved value in directive. cannot use isolated scope here due other reasons.

thanks in advance

you can use $observe observe value changes of attributes contain interpolation (e.g. src="{{bar}}"). not efficient it's way actual value because during linking phase interpolation hasn't been evaluated yet , value @ time set undefined.

post: function (scope, element, attrs) {     attrs.$observe('id', function (id) {         console.log(id)     }) } 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -