Why angular can't deal with NaN value passed to directive?
314 views
Skip to first unread message
Artur Nowakowski
unread,
Jun 19, 2014, 6:22:47 AM6/19/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ang...@googlegroups.com
I've tried to answer the question on stackoverflow (http://stackoverflow.com/questions/24271524/angular-js-nan-handling) and I've seen strange behavior of angular directive when NaN value is passed to directive's scope. I can't explain why does it happen, so maybe you could explain it to me.
It's the directive code:
.directive('test',function(){
return{
restrict: 'E',
template: '<span>Test directive number = {{number}}</span>',
scope: {
number: '='
},
link: function(scope,elem,attrs){
scope.number = scope.number || 10;
}
}
});
If I pass NaN as number attribute, link function cannot manipulate with "scope.number" variable. If I try to change its value even by simply "scope.number = 5", nothing happens.
Is it a bug in angular or an expected behavior? Why does it happen?