angularjs 1.5 injecting service in a component - uknown provider errorShare data between AngularJS controllersAngularJS : Prevent error $digest already in progress when calling $scope.$apply()How can I test an AngularJS service from the console?AngularJS: Service vs provider vs factoryAngularJS : Factory and Service?Uncaught Error: Unknown provider: $rootScopeProvider <- $rootScopeCannot inject angular cookies - Unknown provider errorcomponent service not being injected into test in jasmineIssue with ngRoute injecting resolve services into component controllerAngularJS Unknown Provider Error MessageAngularjs - Move service code to another file

Is the decompression of compressed and encrypted data without decryption also theoretically impossible?

How do I calculate APR from monthly instalments?

How would you say “AKA/as in”?

How to make thick Asian sauces?

How can I instantiate a lambda closure type in C++11/14?

Did thousands of women die every year due to illegal abortions before Roe v. Wade?

How to decline physical affection from a child whose parents are pressuring them?

Pronoun introduced before its antecedent

Do adult Russians normally hand-write Cyrillic as cursive or as block letters?

Is it legal in the UK for politicians to lie to the public for political gain?

Bent spoke design wheels — feasible?

What is in `tex.print` or `tex.sprint`?

What are the words for people who cause trouble believing they know better?

Can a magnetic field of an object be stronger than its gravity?

On the Twin Paradox Again

Are there cubesats in GEO?

C SIGINT signal in Linux

Is there any word or phrase for negative bearing?

What happened to all the nuclear material being smuggled after the fall of the USSR?

How can drunken, homicidal elves successfully conduct a wild hunt?

Movie where a boy is transported into the future by an alien spaceship

What's the correct term describing the action of sending a brand-new ship out into its first seafaring trip?

How to supress loops in a digraph?

Why is c4 bad when playing the London against a King's Indian?



angularjs 1.5 injecting service in a component - uknown provider error


Share data between AngularJS controllersAngularJS : Prevent error $digest already in progress when calling $scope.$apply()How can I test an AngularJS service from the console?AngularJS: Service vs provider vs factoryAngularJS : Factory and Service?Uncaught Error: Unknown provider: $rootScopeProvider <- $rootScopeCannot inject angular cookies - Unknown provider errorcomponent service not being injected into test in jasmineIssue with ngRoute injecting resolve services into component controllerAngularJS Unknown Provider Error MessageAngularjs - Move service code to another file






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I want to share a specific property across different components' (different controllers in them).



Trying to inject a service that I created in the app module.
The service has get/set functions.
I created the service called SharedProperties. It's not accessible from any component in my app, says "Uknown". Why?



This is how my app is defined, and here's the very simple service.



mapotApp = angular
.module('mapotApp', [])
.service('sharedProperties', function ()
var property = 'test';
return
getProperty: function ()
return property;
,
setProperty: function(value)
property = value;

;
);


and then in my component:



angular.module('aboutPage').component('aboutPage', 
templateUrl: 'app/about-page/about-page.html',
controller: ['sharedProperties', function AboutPageController($http, $scope, sharedProperties)
var self= this;

//inherting global variable

self.prop = sharedProperties.getProperty(); //UNKOWN PROVIDER ERROR HERE


]

);


This returns:



Error: [$injector:unpr] Unknown provider: sharedPropertiesProvider <- sharedProperties


What can I do?
I tried injecting it in tons of places and still doesn't work.
thanks so much.










share|improve this question
























  • Add the service to your module aboutPage

    – Anurag Srivastava
    Mar 24 at 15:37











  • I did, as you can see it's injected. But I want the service to be used by many controllers, not written again in each one

    – Thomas
    Mar 24 at 15:38











  • Then use just angular.service('sharedProperties', function () ), without adding to any module.

    – Anurag Srivastava
    Mar 24 at 15:39











  • Where should I put it exactly? Can you write the code with it? Thanks!

    – Thomas
    Mar 24 at 15:40











  • See this link - medium.com/@ok.bayat/…

    – Anurag Srivastava
    Mar 24 at 15:42

















0















I want to share a specific property across different components' (different controllers in them).



Trying to inject a service that I created in the app module.
The service has get/set functions.
I created the service called SharedProperties. It's not accessible from any component in my app, says "Uknown". Why?



This is how my app is defined, and here's the very simple service.



mapotApp = angular
.module('mapotApp', [])
.service('sharedProperties', function ()
var property = 'test';
return
getProperty: function ()
return property;
,
setProperty: function(value)
property = value;

;
);


and then in my component:



angular.module('aboutPage').component('aboutPage', 
templateUrl: 'app/about-page/about-page.html',
controller: ['sharedProperties', function AboutPageController($http, $scope, sharedProperties)
var self= this;

//inherting global variable

self.prop = sharedProperties.getProperty(); //UNKOWN PROVIDER ERROR HERE


]

);


This returns:



Error: [$injector:unpr] Unknown provider: sharedPropertiesProvider <- sharedProperties


What can I do?
I tried injecting it in tons of places and still doesn't work.
thanks so much.










share|improve this question
























  • Add the service to your module aboutPage

    – Anurag Srivastava
    Mar 24 at 15:37











  • I did, as you can see it's injected. But I want the service to be used by many controllers, not written again in each one

    – Thomas
    Mar 24 at 15:38











  • Then use just angular.service('sharedProperties', function () ), without adding to any module.

    – Anurag Srivastava
    Mar 24 at 15:39











  • Where should I put it exactly? Can you write the code with it? Thanks!

    – Thomas
    Mar 24 at 15:40











  • See this link - medium.com/@ok.bayat/…

    – Anurag Srivastava
    Mar 24 at 15:42













0












0








0








I want to share a specific property across different components' (different controllers in them).



Trying to inject a service that I created in the app module.
The service has get/set functions.
I created the service called SharedProperties. It's not accessible from any component in my app, says "Uknown". Why?



This is how my app is defined, and here's the very simple service.



mapotApp = angular
.module('mapotApp', [])
.service('sharedProperties', function ()
var property = 'test';
return
getProperty: function ()
return property;
,
setProperty: function(value)
property = value;

;
);


and then in my component:



angular.module('aboutPage').component('aboutPage', 
templateUrl: 'app/about-page/about-page.html',
controller: ['sharedProperties', function AboutPageController($http, $scope, sharedProperties)
var self= this;

//inherting global variable

self.prop = sharedProperties.getProperty(); //UNKOWN PROVIDER ERROR HERE


]

);


This returns:



Error: [$injector:unpr] Unknown provider: sharedPropertiesProvider <- sharedProperties


What can I do?
I tried injecting it in tons of places and still doesn't work.
thanks so much.










share|improve this question
















I want to share a specific property across different components' (different controllers in them).



Trying to inject a service that I created in the app module.
The service has get/set functions.
I created the service called SharedProperties. It's not accessible from any component in my app, says "Uknown". Why?



This is how my app is defined, and here's the very simple service.



mapotApp = angular
.module('mapotApp', [])
.service('sharedProperties', function ()
var property = 'test';
return
getProperty: function ()
return property;
,
setProperty: function(value)
property = value;

;
);


and then in my component:



angular.module('aboutPage').component('aboutPage', 
templateUrl: 'app/about-page/about-page.html',
controller: ['sharedProperties', function AboutPageController($http, $scope, sharedProperties)
var self= this;

//inherting global variable

self.prop = sharedProperties.getProperty(); //UNKOWN PROVIDER ERROR HERE


]

);


This returns:



Error: [$injector:unpr] Unknown provider: sharedPropertiesProvider <- sharedProperties


What can I do?
I tried injecting it in tons of places and still doesn't work.
thanks so much.







javascript angularjs angularjs-service






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 16:17









Anurag Srivastava

3,44731322




3,44731322










asked Mar 24 at 14:20









ThomasThomas

11




11












  • Add the service to your module aboutPage

    – Anurag Srivastava
    Mar 24 at 15:37











  • I did, as you can see it's injected. But I want the service to be used by many controllers, not written again in each one

    – Thomas
    Mar 24 at 15:38











  • Then use just angular.service('sharedProperties', function () ), without adding to any module.

    – Anurag Srivastava
    Mar 24 at 15:39











  • Where should I put it exactly? Can you write the code with it? Thanks!

    – Thomas
    Mar 24 at 15:40











  • See this link - medium.com/@ok.bayat/…

    – Anurag Srivastava
    Mar 24 at 15:42

















  • Add the service to your module aboutPage

    – Anurag Srivastava
    Mar 24 at 15:37











  • I did, as you can see it's injected. But I want the service to be used by many controllers, not written again in each one

    – Thomas
    Mar 24 at 15:38











  • Then use just angular.service('sharedProperties', function () ), without adding to any module.

    – Anurag Srivastava
    Mar 24 at 15:39











  • Where should I put it exactly? Can you write the code with it? Thanks!

    – Thomas
    Mar 24 at 15:40











  • See this link - medium.com/@ok.bayat/…

    – Anurag Srivastava
    Mar 24 at 15:42
















Add the service to your module aboutPage

– Anurag Srivastava
Mar 24 at 15:37





Add the service to your module aboutPage

– Anurag Srivastava
Mar 24 at 15:37













I did, as you can see it's injected. But I want the service to be used by many controllers, not written again in each one

– Thomas
Mar 24 at 15:38





I did, as you can see it's injected. But I want the service to be used by many controllers, not written again in each one

– Thomas
Mar 24 at 15:38













Then use just angular.service('sharedProperties', function () ), without adding to any module.

– Anurag Srivastava
Mar 24 at 15:39





Then use just angular.service('sharedProperties', function () ), without adding to any module.

– Anurag Srivastava
Mar 24 at 15:39













Where should I put it exactly? Can you write the code with it? Thanks!

– Thomas
Mar 24 at 15:40





Where should I put it exactly? Can you write the code with it? Thanks!

– Thomas
Mar 24 at 15:40













See this link - medium.com/@ok.bayat/…

– Anurag Srivastava
Mar 24 at 15:42





See this link - medium.com/@ok.bayat/…

– Anurag Srivastava
Mar 24 at 15:42












1 Answer
1






active

oldest

votes


















0














Here is the working DEMO with your code.



Your shareable service is correct, but make sure to properly initialize your controller, as well as correctly inject $http and $scope in it (see how $scope and $timeout services are injected in my demo).






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55324747%2fangularjs-1-5-injecting-service-in-a-component-uknown-provider-error%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Here is the working DEMO with your code.



    Your shareable service is correct, but make sure to properly initialize your controller, as well as correctly inject $http and $scope in it (see how $scope and $timeout services are injected in my demo).






    share|improve this answer



























      0














      Here is the working DEMO with your code.



      Your shareable service is correct, but make sure to properly initialize your controller, as well as correctly inject $http and $scope in it (see how $scope and $timeout services are injected in my demo).






      share|improve this answer

























        0












        0








        0







        Here is the working DEMO with your code.



        Your shareable service is correct, but make sure to properly initialize your controller, as well as correctly inject $http and $scope in it (see how $scope and $timeout services are injected in my demo).






        share|improve this answer













        Here is the working DEMO with your code.



        Your shareable service is correct, but make sure to properly initialize your controller, as well as correctly inject $http and $scope in it (see how $scope and $timeout services are injected in my demo).







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 7:02









        NadíNadí

        469212




        469212





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55324747%2fangularjs-1-5-injecting-service-in-a-component-uknown-provider-error%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript