Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to call multi function in single ng-init directice using angularjs

I just try to call two function in single ng-init of angularjs.but it through error to me. My code:

ng-init="function1();function2();"

I don't know how to call those function correctly.anyone can give me some ideas to do it.
Thanls advance..

like image 729
Udaya Ravi Avatar asked Feb 11 '15 06:02

Udaya Ravi


2 Answers

You can create one main function like "init" and call other functions inside that function.

ng-init="init()"

from your controller

function init() {
  function1();
  function2();
}
like image 67
Sandeeproop Avatar answered Sep 20 '22 18:09

Sandeeproop


Check out the below link, and have a look at the console.

http://plnkr.co/edit/60Ry6hwiunAF12PZclNW?p=preview

HTML

<div ng-init='one(); two();'></div>

JS

$scope.one = function(){
  console.log('one')
};

$scope.two = function(){
  console.log('two')
};

Hope this is what you are expecting

like image 31
Rajeshwar Avatar answered Sep 19 '22 18:09

Rajeshwar