Warum wird AngularJS die Funktion name () zweimal aufrufen?
Der Code ist einfach:
<!doctype html>
<html ng-app="plunker" >
<head>
<meta charset="utf-8">
<title>AngularJS Plunker</title>
<script>document.write("<base href=\"" + document.location + "\" />");</script>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js"></script>
</head>
<body ng-controller="MainCtrl">
Hello {{name()}}!
</body>
</html>
<script>
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name= function() {
console.log("---name---:" + new Date());
return "Freewind";
};
});
</script>
Sie können sehen, dass es eine gibtname
funktionieren und wir rufen es nur einmal im Körper auf. Aber in der Konsole wird zweimal gedruckt---name---:
:
---name---:Wed Feb 20 2013 14:38:12 GMT+0800 (中国标准时间)
---name---:Wed Feb 20 2013 14:38:12 GMT+0800 (中国标准时间)
Hier können Sie eine Live-Demo sehen:http://plnkr.co/edit/tb8RpnBJZaJ73V73QISC?p=preview
Warum die Funktionname()
wurde zweimal aufgerufen?