angularjs - Passing arguments to factory -
i building app using angularjs.
i have function (createstarmarkup) returns bunch of html based on number.
function(rating) { var rating = number(rating); var markup = ""; //do stuff return markup; }
i able use function multiple places in application, defined service in utility module.
var app = angular.module('utilities', []); app.factory('createstarmarkup', function(rating) { var rating = number(rating); var markup = ""; // stuff return markup; });
i add 'utilities' module dependency 1 of other modules, , inject service controller.
var app = angular.module('reviews', ['ionic', 'utilities']); app.controller('reviewcontroller', ['$scope', '$ionicactionsheet', 'createstarmarkup', function($scope, $ionicactionsheet, createstarmarkup){...});
this produces following error
error: [$injector:unpr] unknown provider: $ratingprovider <- $rating <- createstarmarkup
the error goes away if remove rating parameter in createstarmarkup function. on right track using factory or should else?
your factory definition not valid. please change follows
app.factory('createstartupservices', ['', function() { return { getmarkup: function(rating) { var rating = number(rating); var markup = ""; // stuff return markup; }, } } ]);
and controller, need method getmarkup
follows
var app = angular.module('reviews', ['ionic', 'utilities']); app.controller('reviewcontroller',['$scope', '$ionicactionsheet', 'createstartupservices', function($scope, $ionicactionsheet, createstartupservices){ //createstartupservices.getmarkup(123); });
Comments
Post a Comment