angularjs - How to access wrapped variables in a directive? -
i have object consists of multiple arrays:
$scope.myarrays = {     array1: ['pizza', 'spaghetti'],     array2: ['lasagne', 'schnitzel'] }; moreover, have custom directive want pass object myarrays , bind arrays scope variables:
<my-directive my-data="myarrays"></my-directive> myapp.directive('mydirective', function() {     return {         restrict: 'e',         scope: {             arrayone: '=mydata.array1',             arraytwo: '=mydata.array2'         },         link: function(scope, elem) {             // access scope.array1 , scope.array2         }     }; }); is there way bind arrays directly or need bind arrays: '=myarrays' , access them arrays.array1?
binding has 1 one, cannot that. yes, have access arrays inside directive.
myapp.directive('mydirective', function() {     return {         restrict: 'e',         scope: {             mydata: '='         },         link: function(scope, elem) {            scope.arrayone = scope.mydata.array1;            scope.arraytwo = scope.mydata.array2;         }     }; }); you can directly access scope.mydata.array1 , scope.mydate.array2 inside directive template if dont have process these arrays in link function , rid of it.
Comments
Post a Comment