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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현