How Do You Pass Parameters To An Angularjs Factory?
I have an AngularJS factory that encapsulates a websocket connection. I want to have a number of these used in my controller with each connecting to a different endpoint (specified
Solution 1:
update I'm sorry I actually misunderstood you a bit. Define your Person constructor as normal, i.e.
functionPerson(id) {
var ws = newWebsocket('some url ' + id);
}
then inject into a factory
app.factory('PersonFactory', function () { returnPerson; });
then in your controller
app.controller('MyCtrl', function ($scope, PersonFactory) {
$scope.person1 = new PersonFactory(1);
$scope.person2 = new PersonFactory(2);
}
et voila'.
Post a Comment for "How Do You Pass Parameters To An Angularjs Factory?"