AngularJS NaN binding bug
HTML
<script src="http://ci.angularjs.org/view/AngularJS/job/angular.js-angular-master/3034/artifact/build/angular.js"></script>
<div ng-controller="MainController">
<button ng-click="random1()">Random (controller)</button>
{{ myNumber1 }}
</div>
<my-directive number="myNumber2"></my-directive>
{{ myNumber2 }}
JavaScript
var app = angular.module('myApp', []);
app.controller("MainController", function ($scope) {
$scope.myNumber1 = NaN;
$scope.random1 = function () {
$scope.myNumber1 = Math.floor(Math.random() * 100);
};
});
app.directive("myDirective", function () {
return {
template: "<button ng-click='random2()'>Random (directive)</button>",
scope: {
number: "="
},
link: function (scope, element, attrs) {
andba //Comment this line and the binding will work.
scope.number = NaN;
scope.random2 = function () {
scope.number = Math.floor(Math.random() * 100);
};
}
};
});