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;
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
|
show 5 more comments
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
Add the service to your moduleaboutPage
– 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 justangular.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
|
show 5 more comments
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
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
javascript angularjs angularjs-service
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 moduleaboutPage
– 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 justangular.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
|
show 5 more comments
Add the service to your moduleaboutPage
– 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 justangular.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
|
show 5 more comments
1 Answer
1
active
oldest
votes
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).
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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).
add a comment |
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).
add a comment |
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).
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).
answered Mar 26 at 7:02
NadíNadí
469212
469212
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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