Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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>


Test : {{mytest()}}


<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>
HTML

Posted
Comments
John C Rayan 6-Oct-15 8:58am    
I don't think your code will work. You have to add

ng-app="myApp" ng-controller="myCtrl" in body. See below for the amended code.

1 solution

XML
<!DOCTYPE html>

<html>

<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>

<body ng-app="myApp" ng-controller="myCtrl">







Test : {{mytest()}}





<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>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900