Is there a way for me to pass an object array to a directive and have it output specific fields that I specify at the location where I use the directive?
Let's look at an example:
//directive
app.directive('MyDirective', function() {
return {
restrict: 'A',
templateUrl: 'my-directive.html',
scope: {
items: '@',
field: '@'
}
};
});
// my-directive.html template
<div ng-repeat="item in items">{{ item.field }}</div>
The concept is to be able to use it with any object like this:
// object arrays
var phones = [{id:1,number:'555-5555'}, {id:2,number:'555-6666'}];
var persons = [{id:1,name:'John'}, {id:2,name:'Jane'}];
// directive usage
<div my-directive items="phones" data-field="???number???"></div>
<div my-directive items="persons" data-field="???name???"></div>
The desired outcome is to display the phone numbers and names. Is this achievable in Javascript?