Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Services are not injected into scope after ng:include #155

Closed
vojtajina opened this issue Nov 17, 2010 · 5 comments
Closed

Services are not injected into scope after ng:include #155

vojtajina opened this issue Nov 17, 2010 · 5 comments

Comments

@vojtajina
Copy link
Contributor

When you create custom service:
angular.service('custom', function() {}, {$creation: 'eager-published'});

Service should be injected in the scope, so you can call in the template:
test

It works in common page, but not inside included page.
You can test it in doc - @example as doc is loaded by ajax....
To get it work, you need to add controller, inject the service into the controller and call it through the controller.

@IgorMinar
Copy link
Contributor

can you create a test case at http://jsfiddle.net/ plz?

@IgorMinar
Copy link
Contributor

actually that won't be possible (because of the xhr request). can you create an angular spec for this instead? thanks!

@vojtajina
Copy link
Contributor Author

I have written a scenario test for that and realized that:

  • when including a template with ng:include, it's not evaluated (that's ok, as it's a template), so when you include a template with script, nothing happens
  • in doc, doc:example widget evals the content and when this happens, root scope is already initialized (with injected services), so if you define new service (even with eager-published) it's not injected in the scope, so you need to use it through controller

So this issue is related only to doc. We should consider whether doc:example widget should manage to inject services.
What's your opinion on that ?

If so, I will write a scenario test for that: test including html template with doc:example (with defined service inside) and test whether the service is defined in the scope...

@IgorMinar
Copy link
Contributor

we recently made a change to get away with the published services completely.

in my opinion services should only rarely be used in view directly (that was one of the reasons why we removed the support for published services). going through the controller or having controller inject services needed in a view is much more preferred.

I think we can close this issue as not relevant any more. if you think otherwise feel free to discuss it and we can reopen it again.

@vojtajina
Copy link
Contributor Author

Agree, removing published services is good step !
Users should inject them into controllers and use controllers in the view.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants