How I solved it using Blesh's answer
Template:
<body ng-app="address" ng-controller="AddressCtrl" scroll-spy="addresses"> <div class="container"> <form ng-submit="lookupAddress()"> <input type="text" ng-model="addressText" /> <button id="addressQueryBtn">Submit</button> </form> <div id="addressList"> <ul> <li ng-repeat="addr in addresses">{{addr}}</li> </ul> </div> </div> </body>
Angular JS:
angular.module('address', []). directive('scrollSpy', function($timeout){ return function(scope, elem, attr) { scope.$watch(attr.scrollSpy, function(value) { $timeout(function() { elem.scrollspy('refresh') }, 200); }, true); } }); function AddressCtrl($scope, $http) { $scope.addresses = []; $scope.lookupAddress = function() { $scope.addresses.push($scope.addressText); $scope.addressText = ''; }; }
The third argument to scope.watch (...) is needed when the observed region var is an object or an array. Unfortunately, this solution still leads to the unrecognized problem of expressing randomguy in the comments. I eventually resolved this using a timeout in the clock function.
Steve goodman
source share