I made a custom directive in angularjs with an isolated scope and passing argument. I try to check the argument in the controller/link of the directive because some times the argument is an array and i need only one item. but this don't work ( undefined object ).
- my directive :
directives.directive('dir.displaytaxoname', function () { return { restrict: 'E', replace: true, scope: { dfamily: '@' , dgenus: '@', dsn: '@' }, controller: function ($scope) { console.log($scope.dsn); // empty string in the console but ok in the rendered view /*function tools_isArray(arr) { return ( arr instanceof Array ); }*/ // if the dfamily argument is an array i just want the first item if(tools_isArray($scope.dfamily)){ $scope.dfamily = $scope.dfamily[0]; } if(tools_isArray($scope.dgenus)){ $scope.dgenus = $scope.dgenus[0]; } if(tools_isArray($scope.dsn)){ cl("indsn") ; $scope.dsn = $scope.dsn[0]; } }, templateUrl: "partials/elements/displaytaxoname.html" } }); - my templete :
<span> {{dfamily}} <i ng-show="dgenus!=''">{{dgenus}} </i><i>{{dsn}}</i><br> </span> - call to the directive :
<dir.displaytaxoname dfamily="{{specimen['T_FAMILY']}}" dgenus="{{specimen['T_GENUS']}}" dsn="{{specimen['T_SCIENTIFICNAME']}}"> </dir.displaytaxoname> I try many combinaison with link/controller but don't work. How can i do please ?
thanks