0

I am a newbie to Angularjs as well as Javascript. Want to know how to pass some values to the angular controller. I have an external javascript function which contains the data and I want to use the value in the javascript functions defined inside the angularjs controller.

Please help me to get this done..

Pradeep
  • 753
  • 7
  • 15
  • 25
  • http://stackoverflow.com/questions/10490570/call-angular-js-from-legacy-code/10508731#10508731 – Chandermani Mar 27 '14 at 14:58
  • 1
    Consider my advice, please : Please play around a bit with plain JavaScript, maybe a month or a bit more, before taking a framework or an UI library. It will be really helpful for you. – Tudor Zgureanu Mar 27 '14 at 15:01

1 Answers1

1

First off, in many cases you can just reference the object inside your Angular controller:

myObject.data();

You don't want to do this because then you are adding an undefined dependency to your controller, and that will cause trouble when trying to unit test your code. I believe undefined dependencies can cause issues when it comes to code maintenance too.

You could also wrap your custom object in an Angular Service. Something like this:

angularApp.factory('myCustomService', function(){
        return new myCustomObject();
    }
);

Then you can pass this object into the controllers:

function myController($scope,myCustomService) {}

I have used this when dealing with JavaScript code generated by WebORB.

JeffryHouser
  • 39,401
  • 4
  • 38
  • 59