+2 votes
1 view
in Web Technology by (47.8k points)

I understand AngularJS runs through some code twice, sometimes even more, like $watch events, constantly checking model states etc.

However my code:

function MyController($scope, User, local) { 

var $scope.User = local.get(); // Get locally save user data User.get({ id: $scope.User._id.$oid }, function(user) { $scope.User = new User(user); 




Is executed twice, inserting 2 records into my DB. I'm clearly still learning as I've been banging my head against this for ages!

1 Answer

+2 votes
by (107k points)
edited by

For combating AngularJS executing controller twice the you can use the below-mentioned code:-

Looking for Angularjs material from basics! Refer to this video on Angularjs provided by Intellipaat:


templateUrl: 'pages/home.html',

controller: MyController });

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !