1

http://plnkr.co/edit/a9ayjHwPjQaFNnuEB4oC?p=preview

var app = angular.module('plunker', []);



app.controller('MainCtrl', ['$scope', '$http', 'extraService', function ($scope,$http,extraService) {
  $scope.name = 'World'; 
console.log(extraService);
}]);


app.service('extraService',function(){
  return 'abc';
});

Why is it not returning "abc" in my console?

Lee shienlong
  • 69
  • 1
  • 1
  • 6
  • Read and learn that http://stackoverflow.com/questions/15666048/service-vs-provider-vs-factory – nada Jul 20 '15 at 14:01
  • Change `app.service` to `app.factory` and see that post ^. – m59 Jul 20 '15 at 14:02
  • @m59 can explain? I want to use service instead of factory – Lee shienlong Jul 20 '15 at 14:10
  • @Leeshienlong Read the link, please. A factory returns a service. What you want, if you want this syntax, is a factory. In other words, you attempted to use a service created by a factory, but you used `app.service`, which is incorrect. http://plnkr.co/edit/1Xen6Evk7T6R87WSPTvx?p=preview – m59 Jul 20 '15 at 16:06

0 Answers0