Click here to Skip to main content
13,629,993 members
Rate this:
 
Please Sign up or sign in to vote.
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>

		
Posted 3-Oct-15 3:46am
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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

<!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>
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.180712.1 | Last Updated 6 Oct 2015
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100