javascript - Angular Service is injected into controller, but it appears as an empty object -
i have following angular service.
angular.module('myapp') .service('statusservice', function statusservice() { var statusservice= { show: 'off', on: function() { this.show = 'on'; }, off: function() { this.show = 'off'; } }; return statusservice; });
which injected controller, , on function invoked, this:
angular.module('myapp') .controller('acontroller', function (statusservice) { statusservice.on(); })
but following error.
typeerror: object #<object> has no method 'on'
you problem if declared multiple service same name in different places, got confused , return {}.
Comments
Post a Comment