Wednesday, 15 January 2014

javascript - Boolean value not being passed in Angular -



javascript - Boolean value not being passed in Angular -

i'm trying relatively simple here, pass in boolean variable multiexpandable downwards recursive tree created directive. variable later evaluated service. in service keeps coming undefined whatever reason.

i have no thought why doing me! application variable takes in string object , does, literally, same thing , absolutely fine. code below, note lot of has been trimmed show important. why happening?

my directive:

.directive("navigation", function() { homecoming { restrict: 'e', replace: true, scope: { menu: '=', multiexpandable: '=', application: '=', }, controller: function($scope) { $scope.toggleexpand = navigationservice.toggleexpand; }, ... }

my template:

<ul style="list-style: none"> <li ng-repeat="node in menu.folders"> {{multiexpandable}} <i class="fa" ng-click="toggleexpand(node, application, menu, multiexpandable)"></i> <navigation menu="node" application="application" multiexpandable="multiexpandable" ng-show="node.expanded == true"></navigation> </li> </ul>

where directive called:

<navigation class="nav tree" menu="applications[currentapplication].menu" application="currentapplication" multiexpandable="expandable"></navigation>

and value in service (the console log statement returning undefined):

_toggleexpand = function (application, multiexpandable) { //some code console.log("in toggle expand - multiexpandable:"); console.log(multiexpandable); //some code }

your directive attribute declaration camelcase , hence need dash in html this:

multi-expandable="multiexpandable"

note angular:

strip x- , data- front end of html element/attributes, and converts html attributes :, -, or _-delimited name camelcase.

you can read more here:

https://docs.angularjs.org/guide/directive

javascript angularjs

No comments:

Post a Comment