javascript - How can I pass non-string values to Angular directives? -


i have custom angular directive graphically represents “activity” in webapp. use this:

<activity-box ng-repeat="act in activities"     model="act" active="{{currentactivity == act}}" /> 

my directive has isolated scope , declares model , active this:

appdirectives.directive('activitybox', function() {     return {         template: '<div ng-class="{activityactive: active == \'true\'}">{{model.name}}</div>',         restrict: 'e',         replace: true,         scope: {             model: '=',             active: '@'         },         link: ...     }; }); 

i have no worry model attribute, active attribute treated string. when currentactivity == act true, active holds string value "true" (and not boolean true), or else, "false" (and not false).

this means although conceptually boolean, must treat string. instance, i'd write ng-class="{activityactive: active}" instead ng-class="{activityactive: active == 'true'}". right now, if forget part, evaluate true, both "false" , "true" truthy.

is there way me obtain non-string attributes this? what's best way achieve this?

what about?

<activity-box ng-repeat="act in activities"     model="act" active="currentactivity == act" />  scope: {             model: '=',             active: '='         }, 

just tried - works. , has binding, if 'currentactivity' or 'act' change, value of 'active' inside directive change.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -