AngularJS - Add computation value from a function to the scope

梦想与她 提交于 2019-12-06 13:04:30
Phil

Set up a watch listener for changes to the days difference expression, eg

HTML

<input type="text" name="numberOfDays" ng-model="numberOfDays" />

Controller

$scope.$watch(function() {
    return Math.floor(($scope.endDate - $scope.startDate) / 86400000);
}, function(days) {
    $scope.numberOfDays = days;
});

Simplified days calculation taken from here - https://stackoverflow.com/a/544429/283366

Plunker example here - http://plnkr.co/edit/MPNh7O?p=preview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!