AngularJS 中的调用函数进入无限循环 [英] Calling function inside AngularJS goes in endless loop
问题描述
我是 AngularJS 的新手,我正在构建一个示例应用程序.我想在我的网页上显示谷歌地图响应的结果.在这里,我传递了示例值,但页面继续循环并给出以下错误:Error: [$rootScope:infdig] 10 $digest() 迭代达到.中止!
var app = angular.module('myApp', ['ui.bootstrap']);app.controller('myCon', function($scope, $http) {$scope.getAddress = 函数(网址){return $http.get('https://maps.googleapis.com/maps/api/distancematrix/json?origins=Toronto+ON&destinations='+url+'&mode=driving').then(function(response)){返回 response.rows[0].elements[0].distance.text;});};
这是 HTML 页面:
<html lang="en" ng-app="myApp" ng-controller="myCon"><头><meta charset="UTF-8"><title>Angular Demo</title><script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script><script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.0.js"></script><script src="js/app.js"></script><link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="样式表">头部><身体><div class="page">{{getAddress('渥太华')}}