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         }     }; }); 

all in fiddle play around!

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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -