Passing array via attribute to AngularJS directive Passing array via attribute to AngularJS directive arrays arrays

Passing array via attribute to AngularJS directive


If you're accessing this array from your scope, i.e. loaded in a controller, you can just pass the name of the variable:

Binding array to directive variable in AngularJS

Directive:

scope:{        title: "@",        author: "@",        content: "@",        cover: "@",        date: "@",        tags: "="    },

Template:

<post title="sample title" tags="arrayName" ... >


you can also have to use $scope instead of attrs. then you will get array object, otherwise you will get an string.

     scope:{            title: "@",            author: "@",            content: "@",            cover: "@",            date: "@",            tags: "="        },link: function(scope, element, attrs){            scope.tags = scope.tags        }