Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

model.$modelValue is NaN in directive

Tags:

See this jsfiddle: http://jsfiddle.net/8bENp/66/

If you look at the JavaScript console, you'll see something like this:

TypeError: Object NaN has no method 'replace'     at makeHtml (https://raw.github.com/coreyti/showdown/master/compressed/showdown.js:62:705)     at render (http://fiddle.jshell.net/_display/:50:42)     at link (http://fiddle.jshell.net/_display/:54:13)     at k (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js:42:321)     at e (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js:38:198)     at k (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js:42:261)     at e (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js:38:198)     at https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js:37:332     at https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js:15:440     at Object.e.$eval (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js:85:416) <markdown ng-model="someCode" class="ng-pristine ng-valid"> angular.min.js:60 

The problem is that model.$modelValue is NaN when its type shouldn't even be a number. Nevertheless, the markdown renders. I could add a typeof model.$modelValue == 'string' check, but I'd rather treat the underlying cause. Any idea?