0

I have a function sendData(). My question is can it get executed without invoking it, inside the controller?

Rahil Wazir
  • 10,007
  • 11
  • 42
  • 64
Chetan Shah
  • 129
  • 14
  • possible duplicate of [Angular.js - how to execute function on page load?](http://stackoverflow.com/questions/15458609/angular-js-how-to-execute-function-on-page-load) – Adrian Thompson Phillips Nov 17 '14 at 15:14

2 Answers2

1

No, but you can call it just after declaration.

var sendData = function() {
  //dostuff
}
sendData();
Jaanus
  • 16,161
  • 49
  • 147
  • 202
1

You can wrap your method in self execution name function.

var sendData = (function _() {
  // your stuff

  return _;
})();

It will directly executes and you can also later call it using sendData()

Rahil Wazir
  • 10,007
  • 11
  • 42
  • 64