Angular:重复函数调用 [英] Angular : duplicate function call

查看:70
本文介绍了Angular:重复函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的代码中发现了一些奇怪的东西: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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆