angularjs - Angular: How To Introduce External Domain Objects Into A Controller? -


my application has number of domain model objects i've built , unit tested. there nothing angular-specific them, have no angular dependencies, , use them if had selected other framework besides angular.

my question proper way use them within angular. need use them in controller. i'm including them before angular controller code, defined , can refer them. i'd know if there better way? should using angular's dependency injection system inject them? if so, how?

thanks.

you should stick them in service. can injected / mocked / tested / di-is-fun-ed easily.

before:

var superbigthing = {   isawesome: true; }; 

after:

myapp.factory('superbigthing', function() {   var superbigthing = {     isawesome: true   };   return superbigthing; });  myapp.controller('thingctrl', function($scope, superbigthing) { }); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -