I'm trying to create a custom directive and send an array into it to create a dynamic template. I've looked at these two questions:
Binding array to directive variable in AngularJS
Passing array via attribute to AngularJS directive
I'm using the same code basically but when I console log the tAttrs
it only shows tags as "testArray"
instead of Array(2)
as it would be should the tags="testArray"
be interpreted correctly.
From what I can see I haven't done anything wrong here so it's kinda driving me to insanity why it's not working.
Can someone point out why this isn't working as expected?
The controller containing the array:
forumApp.controller('profileCtrl', ['$scope', function($scope) {
$scope.testArray = ['displayName', 'email'];
}
The directive markup:
<error tags="testArray"></error>
And the directive:
forumApp.directive('error', [function() {
return {
restrict: 'E',
scope: {
tags: "="
},
template: function(tElement, tAttrs) {
console.log(tAttrs);
return "<div ng-if='row.model === " + tAttrs.tags[0] + "'>Hello world</div>";
}
}
}]);