Angular:重复函数调用 [英] Angular : duplicate function call
问题描述
我在下面的代码中发现了一些奇怪的东西:mytest函数被调用了3次!为什么?
<!DOCTYPE html>
< html>
< script src = http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js\"></script>
< body>
I found some weird things in below code: the mytest function is called 3 times!!! WHY ?
<!DOCTYPE html>
<html>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
测试:{{mytest()}}
Test : {{mytest()}}
< script>
var app = angular.module('myApp',[]);
app.controller('myCtrl ',function($ scope){
$ scope.name =John;
$ scope.mytest = function(){
console.log('我的测试');
返回'某事';
};
});
< / script>
< / body>
< / html>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.name= "John ";
$scope.mytest = function () {
console.log('my test');
return 'something';
};
});
</script>
</body>
</html>
推荐答案
范围){
scope) {
scope.name =John;
scope.name= "John ";
scope.mytest = function(){
console.log('我的测试');
返回'某事';
};
});
< / script>
< / body>
< / html>
scope.mytest = function () {
console.log('my test');
return 'something';
};
});
</script>
</body>
</html>
这篇关于Angular:重复函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!