How do I get this AngularJS service working in my code? -
here code service. taken first answer here.
var myapp = angular.module('myapp', ['ngroute']); myapp.service('sharedproperties',function(){ var property = "first"; return{ getproperty:function(){ return property; }, setproperty:function(value){ property = value; } }; });
here jsfiddle shows code in full , not working.
the error is:
"error: sharedproperties not defined
for line alert on. using alert mere example of showing service working before extend code further.
anyone know why simple example of service not working? i've thoroughly went on code make sure there no typos or silly that.
the answer linked has jsfiddle uses older version of angularjs. able replace version angular being used in jsfiddle , still worked fine doesn't seem version issue.
you need inject service controller:
myapp.controller('maincontroller', function($scope, sharedproperties) {
(minification safe syntax)
myapp.controller('maincontroller', ["$scope", "sharedproperties", function($scope, sharedproperties) {
working fiddle: http://jsfiddle.net/b2fce/733/
Comments
Post a Comment