Uncaught Error: [$rootScope:infdig] when implementing an elapsed time calculator

柔情痞子 提交于 2019-12-06 00:39:30

Looks like I've located the issue. I have an assumption that angular creates new arrays each evaluation so it always fires watcher

function Ctrl2($scope) { $scope.date = new Date(); $scope.format = 'M/d/yy h:mm:ss a'; $scope.options = [$scope.date, $scope.format]; //<--line added }

<div ng-app="time"> <div ng-controller="Ctrl2"> Elapsed time: <span my-current-time="options"></span> //<-- binding change. </div> </div>

updated fiddle

ADDED

Also not sure that you really need this watch functionality. Bear in mind that watch works on whole array in your case not inner elements. You can extract value this scope.$eval(attrs.myCurrentTime).

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