javascript - Angular calculation not updating in view -


i creating small application calculates distance between 2 points. console.log outputs calculation correctly, not angular portion in view. after click or second selection. i've setup 2 select fields (with separate ng-models) filled information out of json file. i've searched internet extensively, can't find answer. can me this... :) code:

var app = angular.module('calculateapp', []); app.controller('calculatecontroller', function($scope, $http) {     $http.get('json/stops.json')         .then(function(item){         $scope.stations = item.data;         $scope.station1 = false;         $scope.station2 = false;         // watch , calculate         $scope.$watch(              function( $scope ) {                 function distance(lat1, lon1, lat2, lon2) {                   var r = 6371;                   var =                       0.5 - math.cos((lat2 - lat1) * math.pi / 180)/2 +                       math.cos(lat1 * math.pi / 180) * math.cos(lat2 * math.pi / 180) *                       (1 - math.cos((lon2 - lon1) * math.pi / 180))/2;                   return r * 2 * math.asin(math.sqrt(a));                 }                 console.log(distance($scope.station1.stop_lat, $scope.station1.stop_lon, $scope.station2.stop_lat, $scope.station2.stop_lon));                 $scope.calculated = distance($scope.station1.stop_lat, $scope.station1.stop_lon, $scope.station2.stop_lat, $scope.station2.stop_lon);             }         );         // end calculate     }); }); 

i use in html file:

total distance is: {{calculated}}

first of in watch dont need send scope function can send newvalue, oldvalue those.

i think removing $scope watch function solved

edit:

i see want watch scope dont need function $scope

look @ this think you.

and not sure if can watch whole scope should select thing need watch.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -