javascript - Invoke function in HTML which is defined in controller -


how possible invoke function when html page loaded? right now, function call made manually pressing button, like:

<p>     {{address}} </p>  <button class="btn btn-primary checkout" ng-click="getaddress()">      <i class="fa"> address</i> </button> 

it possible call function using {{getaddress()}}. but, expected causes infinite loop.

getaddress() makes call backend, gets data , populates address on $scope ($scope.address)

it nice load automatically , rid off button.

in controller can invoke getaddress(). might have controller following

myapp.controller('yourcontroller', function($scope){         $scope.address = "";         $scope.getaddress = function(){            $scope.address = "some address";          };         //you can call here itself, invoked when page , in  turn script loads         $scope.getaddress(); }); 

Comments

Popular posts from this blog

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -