How do I access the headerInput model from within the sideMenuContent directive? Let's say I have 10 other ng-models in sideMenuHeader directive that I want to access in sideMenuContent, is there any way of making it easily scalable?
1 Answer
You need to use the dot notation for objects. See Understanding Scopes in AngularJs
So instead of headerInput, use something like menu.headerInput and also make sure to initialize a menu object in your controller like so $scope.menu = {}; (or you can also set default values).
3 Comments
William Boman
Sweet, this works! It feels a tad ugly though (my fault). What do you think about all of my
ng-transclude's and stuff? I tried to create a boilerplate sideMenu-directive with sub-directives (header and content). Is there a better way of doing what I've tried to do?JoseM
I don't think that it's ugly, you are using
ng-transclude for their intended functionality. The only suggestion I would make is to not have your template all on one line or to separate it out into a templateURL so that it is easier to read.William Boman
Yeah I hate writing HTML as strings in JS, no matter the length of it. I did so on my plnkr because i was lazy :).