user572276
user572276

Reputation: 49

scope value changed but watch did not fire

I use a directive for geolocation input and gives you back the coordinates value in a scope. I want to watch when the scope gets the value so I could do something.

my plnkr

    angular.module('app', ['ngAutocomplete'])
    .directive('myForm', function() {

         return {
            restrict: 'E',
            templateUrl: 'myForm.html',

        };

    }) 
    .controller('formCtrl', function ($scope)
    {
          //watch for details change
         $scope.$watch($scope.details, function () {

            //alert('details changed')
            $scope.formItem.longitude = $scope.details.geometry.location.lng();
            $scope.formItem.latitude = $scope.details.geometry.location.lat();

        }, true);

    });

Upvotes: 0

Views: 34

Answers (1)

byteC0de
byteC0de

Reputation: 5273

Change to this,

$scope.$watch('details', function () {
    //alert('details changed')
    $scope.formItem.longitude = $scope.details.geometry.location.lng();
    $scope.formItem.latitude = $scope.details.geometry.location.lat();
}, true);

Upvotes: 1

Related Questions